Hi all. Just for kicks I thought i'd try to write something like a for loop but using low level A86 syntax (a combination of JMP, CMP and INC). But my problem is that the loop seems to go on forever. I was hoping someone in the forum could point out my error so I can correct it.
JMP start
CRLF db 10, 13, "$" ; contain carriage return (10) and line feed (13) character values
startUp db "How many times do you want to iterate?$"
shutDown db "Press a key to continue...$"
maxVal db "Max value: $"
curVal db "Current Value: $"
count db "0$"
current db "0$"
start:
MOV AH, 09 ;set upper "A" register to output a string
MOV DX, offset startUp
INT 21h
MOV DX, offset CRLF
INT 21h
MOV AH, 08 ;set upper "A" register to read a char
INT 21h
MOV count, AL ; move entered value to count
MOV CX, offset current
MOV BX, offset count
MOV AH, 09 ; get ready to ouput strings
condition:
;current value
MOV DX, offset curVal
INT 21h
MOV DX, CX
INT 21h
MOV DX, offset CRLF
INT 21h
;max value
MOV DX, offset maxVal
INT 21h
MOV DX, BX
INT 21h
MOV DX, offset CRLF
INT 21h
CMP BX, CX ; if BX == CX (COUNT == CURRENT)
JZ finish
iteration:
inc current ;current++
JMP condition ;go back and check the condition again
finish:
MOV AH, 09 ; set upper A to output a string
MOV DX, offset shutDown
INT 21h
MOV DX, offset CRLF
INT 21h
MOV AH, 08 ; getchar() / system("pause")
INT 21h
MOV AH, 4Ch ; set upper A register to quit
MOV AL, 00 ; return 0
INT 21h
Any pointers would be much appreciated. Cheers
The location of
condition:
is wrong as the value of AH cannot be trusted to still be 9. God only knows what is happening when that int 21h is issued,
Paul
as it turns out, AH usually is 9, if i remember
it is BX and CX i would worry about
the point is, you cannot depend on registers being preserved across INT 21h calls, unless the docs specifically say so
a good read of Ralf's may help...
Ralf Brown's Interrupt List:
http://www.cs.cmu.edu/~ralf/files.html
The list is organized in 6 ZIP files (inter61a.zip-inter61f.zip). This is the most complete list of interrupts available.
Most of the information you will need is in the first 2 ZIP files (inter61a.zip and inter61b.zip).
The files are fairly large text files. If you look down the list a little further, there is a program for viewing them.
It is called Ralf Brown Interrupt List Viewer, or simply RBIL Viewer (rbilv21.zip).
The individual text files have names like INTERRUP.A, INTERRUP.B, and so on.
You may want to rename them to something like INT_A.TXT, INT_B.TXT, etc. to make them easier to use.
On my machine, .TXT files open with Notepad, but I have it set up so that .LST files open with WordPad.
The files are rather large and WordPad is better at handling large files, so I renamed mine using the .LST extension.
Ralf's List has a lot of information you may never use, because they try to make it complete.
On the other hand, it is full of useful tables and structure definitions that are hard to find elsewhere.
CMP BX, CX ; if BX == CX (COUNT == CURRENT)
JZ finish
Since BX and CX are addresses and never change, they will never be equal - that's why it's an endless loop.
I think you want the contents at those addresses, try using
mov al,[bx] ;count
cmp al,[cx] ;current
jz finish