我在汇编x86任务中陷入了混乱。 该计划的要求是: 从用户那里得到2个数字,字大小,然后给它们神圣。 打印除法结果和结果中的剩余部分。
我写了一段代码,但是我输入了很多东西。
;get 2 positive numbers
;print the div and leftovers
.MODEL SMALL
.STACK 64
.DATA
num1 dw ?
num2 dw ?
dResult dw ? ;divide result
lResult dw ? ;leftovers from divide result
MSG1 db "enter first number: " ,'$'
MSG2 db "enter second number: " ,'$'
new_line db 0dh, 0ah, '$'
.CODE
main PROC
mov ax, @data
mov ds, ax
call getFirst
call newLine
call getSecond
call newLine
call divide
call printResult
mov ah, 4ch
int 21h
ENDP
;print results
printResult PROC
;print divide result
mov ah, 09
lea dx, dResult
int 21H
call newLine
;print leftovers from divide
mov ah, 09
lea dx, lResult
int 21H
ret
ENDP
;divide 2 numbers
;put the result and leftover in variables
divide PROC
mov ax, num1
cmp ax, num2
jl lower ;if num1 lower then num2
div num2
jmp finish
lower:
mov ax, num2
div num1
finish:
sub ax, '0' ;switch hex to dec
mov dResult, ax
sub dx, '0' ;switch hex to dec
mov lResult, dx
ret
ENDP
getFirst PROC
;print MSG1
mov ah, 09
lea dx, MSG1
int 21H
;get first number input
mov ah, 0AH
lea dx, num1
int 21H
ret
ENDP
getSecond PROC
;print MSG2
mov ah, 09
lea dx, MSG2
int 21H
;get second number input
mov ah, 0AH
lea dx, num2
int 21H
ret
ENDP
;new line
newLine PROC
lea dx, new_line
mov ah, 09
int 21H
ret
ENDP
END main