0

I'm trying to write program in 8086 asm for XT emulator which draws random pixels on screen (1 coordinate axis for now).

10 pixels are drawn along (x=random(),y=100), then delay is run. I'm getting a hang or infinite loop.

I've tried pushing and popping the cx register for loop. Also I've tried executing the built .com file in dos 3.3 debug.com, but as soon as program hits the graphics mode, nothing can be seen on the screen. I understand that when I scale the random number by 5 it may produce pixel coordinate out of screen. But the problem is in hang or infinite loop. The delay part was tested separately and works fine, delay is about 3 seconds on my emulator.

Additional info: mc1502 8086 machine for mame emulator, os environment - sigma dos for mc1502 (msdos 3.3 clone), asm - turbo asm 1.0.

;configure for com file
.model tiny
.code
org 100h

start:

;set graphics mode
mov ax, 0004h ;cga 320*200 color on mc1502
int 10h

;put pixel line by coords (rnd)
;start random gen
mov dx, 0abbah  ;init
mov cx, 000ah ;10 times
rnd:
mov ax, dx
mov bx, 001fh
mul bx
add ax, 000dh
mov bx, 4ce3h
div bx ;dx now has a random number

;draw pixel
push cx ;save counter
mov cx, 0064h ;x 2-byte
push dx ;save dx
mov ax, dx ; scaling dx 
mov bl, 5
div bl
mov dx, 0 ;scaled y
mov dl, al ;dl is y
mov ax, 0c02h ;0c drawfunc, 02 color
int 10h ;video int
pop dx
pop cx
loop rnd

;delay
mov cx, 0ffffh
delay:
push cx
mov cx, 000ah
indelay:
nop
loop indelay
pop cx
loop delay

;set text mode 80x25 bw
mov ax, 0000h
int 10h

;exit to dos
mov ax, 4c00h
int 21h
end start

Vadim
  • 1
  • 1
  • 2
    Your divisions are probably overflowing and causing an exception. – Jester May 05 '20 at 17:48
  • Use a debugger to see why this faults and where, or what infinite loop you're stuck in. – Peter Cordes May 05 '20 at 17:52
  • The `dx` can be in 0000..4ce2h range (remainder of div 4ce3h), and then you do `div bl (bl=5)`, i.e. the result doesn't fit into 8bit for anything in range 500h..4ce2h -> exception is raised. (maybe try first to draw 10 pixels at coordinates 3, 6, 9, ...) without random to see the other aspects of code work) – Ped7g May 05 '20 at 17:54
  • @PeterCordes, unfortunately debug.com debugger goes into graphics mode (black screen) and is unusable. – Vadim May 05 '20 at 18:02
  • Then use a better debugger. There must be some way to debug a program that runs in graphics mode, so solve that problem first. At worst you could use BOCHS which has a built-in debugger. Normally you'd use that for debugging a bootloader, but once you find where your DOS `.com` got loaded you can probably use it. e.g. maybe put an infinite loop at the start of your program so execution will be there when you look at the machine state with the debugger, and change IP to be after that loop. Or an `int3` breakpoint. – Peter Cordes May 05 '20 at 18:39
  • Trying to learn asm without using a debugger is like trying to build a robot blindfolded; it's a waste of your time since good debuggers do exist. – Peter Cordes May 05 '20 at 18:40

0 Answers0