I wrote a code that getting from the user 2 numbers and the prog divides the numbers between the big number and small one and returns the complete and remaining part after the divide, I have 2 problems in the code:
The first one its that i dont know how to run on my "resultstr" and "reststr" arrays backwards when i fill them...
And the second problem its that when i insert 1 big number like 40,000 and 2 for example when i fill bx with 40000 in is decimal form and ax with 2 in is decimal form when i do cmp bx,ax and use jg afterwards the program does not jump and i don't get why because 40,000>2
...
.MODEL SMALL
.STACK 100h
.DATA
msg1 db "Please Enter Your First Number:",'$'
msg2 db "Please Enter The Second Number:", '$'
msg3 db "The result of the division is:", '$'
resultstr db 12 dup ('$'),0DH
msg4 db "The rest of the division is:", '$'
reststr db 12 dup ('$'),0DH
Ten dw 10
num1 dw 0
num2 dw 0
num1str db 12,?,12 dup('$'),0DH
num2str db 12,?,12 dup('$'),0DH
.Code
start:
mov ax, @data
mov ds, ax
; Printing Message1 with a lineBreak
lea dx, msg1
mov ah, 09
int 21H
mov dl,0AH
mov ah, 02
int 21H
; Getting The first num1
mov ah, 0AH
lea dx, num1str
int 21H
; Printing Message1 with a lineBreak
lea dx, msg2
mov ah, 09
int 21H
mov dl,0AH
mov ah, 02
int 21H
; Getting The first num2
mov ah, 0AH
lea dx, num2str
int 21H
mov cl,byte ptr num1str + 1 ; puting in cx the len of the num1str
mov ch,0
mov si, offset num1str + 2
xor ax, ax
FirstConvert: ; Here we convert the num1 String input from his ascii value into a intger value...
mul Ten
xor bx, bx
mov bl, [si]
sub bx, '0'
add ax, bx
inc si
loop FirstConvert
add num1, ax ; after we calculate his intger value we put him in num1
mov cl,byte ptr num2str+1 ; puting in cx the len of num2str
mov ch,0
mov si, offset num2str + 2
xor ax, ax
SecondConvert: ; Here we convert the num2 String inpurt from his ascii value into intger value ...
mul Ten
xor bx, bx
mov bl, [si]
sub bl, '0'
add ax, bx
inc si
loop SecondConvert
add num2, ax ;after we calculate his intger value we put him in num2
mov ax, num1 ; In the next 5 lines im going to check who is the bigger number...
mov bx,num2 ; ^^
cmp bx,ax ; ^^
jg BigNum2 ; The case num2 is bigger
jmp BigNum1 ; The case num1 is bigger
BigNum1: ; Here I first organize my numbers and then divide them and then send them to my converters to get their ascii value for the printing...
mov ax,num1
mov bx,num2
div bx
mov num1,ax ; using our values to keep the results.
mov num2,dx ; using our values to keep the results.
jmp Convert1
BigNum2: ; Here I first organize my numbers and then divide them and then send them to my converters to get their ascii value for the printing...
mov ax,num2
mov bx,num1
div bx
mov num1,ax ; using our values to keep the results.
mov num2,dx ; using our values to keep the results.
jmp Convert1
; now im going to convert the integers to their ascii values for the print.
; first lets start with the intger part.
Convert1:
lea si, resultstr ; Si pointing into my resultstr that im going to use for the print...
xor ax,ax
xor bx,bx
xor dx,dx
mov ax, num1 ; Convert to ascii value
cmp ax,10
jl Low10
mov bx, Ten
div bx
add dx,'0'
mov [si],dx
inc si
cmp ax , 0 ; If ax == 0 that mean we dont need to convert anymore digits...
jg Convertor1 ; if ax!=0 go to Convertor1 that going to this action until we got all our digits..
je Convert2
Low10:
add ax,'0'
mov [si], ax
jmp Convert2
Convertor1: ; he same steps we took earlier
cmp ax,10
jl Low10
xor dx,dx
mov bx,Ten
div bx
add dx,'0'
mov [si],dx
inc si
cmp ax,0
jg Convertor1
je Convert2
Convert2: ; Now we doing the same procedure we did for the integer part of the division result
lea di, reststr
mov ax,num2
cmp ax,10
jl Low10B
xor dx,dx
mov bx, Ten
cmp ax, 0 ; in case we have zero rest.
je zero
div bx
add dx,'0'
mov [di],dx
inc di
cmp ax, 0
jg Convertor2
je TheEnd
Low10B:
add ax,'0'
mov [di],ax
jmp TheEnd
Convertor2: ; Allmost same loops ecxept here in the last line we jump into the TheEnd procedure...
cmp ax,10
jl Low10B
xor dx,dx
mov bx,Ten
div bx
zero:
add dx,'0'
mov [di],dx
inc di
cmp ax,0
jg Convertor2
je TheEnd
TheEnd: ; Here we printing our converted^2 results and
lea dx, msg3
mov ah, 09
int 21H
lea dx, resultstr
mov ah,09
int 21H
lea dx, msg4
mov ah, 09
int 21H
lea dx, reststr
mov ah, 09
int 21H
;end the program
mov ah, 4ch
mov al, 0
int 21H
END start