in the code below, i am trying to push a value to jump binary which will then be displayed as binary code. For some reason the code seems to only display 1111 instead of dividing properly and showing the respective binary code for each decimal number in count. Any advice guys?
CURSOR MACRO Col, Row
MOV AH,02
MOV BH,00
MOV DL,Col
MOV DH,Row
INT 10H
ENDM
DISP MACRO MES
MOV AH,09
MOV DX,OFFSET MES
INT 21H
.DATA
.
.
.
N1 DB '1','$'
N2 DB '2','$'
N3 DB '3','$'
N4 DB '4','$'
N5 DB '5','$'
N6 DB '6','$'
N7 DB '7','$'
N8 DB '8','$'
N9 DB '9','$'
COUNT DB 0
.
.
.code
.
.
.
.
MOV COUNT,5
.
.
BINARY: MOV AL,COUNT; 22,39 38 37 36
CBW
DIV TWO
CURSOR 36,22
CMP AH,0
JE ZERO
JNE ONE
ZERO: DISP N0
jmp x
ONE: DISP N1
x:
CBW
DIV TWO
CURSOR 35,22
CMP AH,0
JE ZERO1
JNE ONE1
ZERO1: DISP N0
jmp x1
ONE1: DISP N1
x1:
CBW
DIV TWO
CURSOR 34,22
CMP AH,0
JE ZERO2
JNE ONE2
ZERO2: DISP N0
jmp x2
ONE2: DISP N1
x2:
CBW
DIV TWO
CURSOR 33,22
CMP AH,0
JE ZERO3
JNE ONE3
ZERO3: DISP N0
jmp x3
ONE3: DISP N1
x3:
JMP L0
Here are some pointers to get you on your way.
The
MOV COUNT,5
instruction is placed between the data and so probably a reason to malfunction.Each time you use
DIV N2
you divide by 50 because N2 was defined as a character. Best also define a number 2 withTWO db 2
When you want to compare the remainder of the division you already have destroyed the AH register through the macro call
CURSOR 39,22
The second time you use
DIV N2
the AX register no longer contain a usable value because the macro callsDISP N0
andDISP N1
have put the number 09h in the AH register.To succesfully do a cascade of 4 divisions you must preserve the quotient of each previous division and then use that as the dividend for the following division. See example below.
When you use
DISP N0
to display "0" I think that you need to jump over the instructionDISP N1
because now you are getting both "01".An easy solution for problems 3 and 4 would be to save at least the AX register in both macros.
Solution to the cascade (to be repeated for each division):