【发布时间】:2014-10-20 02:14:47
【问题描述】:
我一直在尝试调试一个小汇编程序,在该程序中我要求除数和除数,并且必须输出商和余数。但是由于某种原因,我的商和余数没有输出到屏幕上。这是我的代码:
segment .data
prompt db "Please enter a number: ", 10
promptLen equ $-prompt
prompt2 db "Please enter the divisor: ", 10
prompt2Len equ $-prompt2
prompt3 db "Your quotient is: ", 10
prompt3Len equ $-prompt3
prompt4 db "Your remainder is: ", 10
prompt4Len equ $-prompt4
segment .bss
inputNum resb 2
inputDiv resb 2
quotient resb 2
remainder resb 2
segment .text
global _start
_start:
mov eax, 4
mov ebx, 1
mov ecx, prompt
mov edx, promptLen
int 80h
mov eax, 3
mov ebx, 0
mov ecx, inputNum
mov edx, 2
int 80h
mov eax, 4
mov ebx, 1
mov ecx, prompt2
mov edx, prompt2Len
int 80h
mov eax, 3
mov ebx, 0
mov ecx, inputDiv
mov edx, 2
int 80h
xor edx, edx
mov ax, [inputNum]
mov bx, [inputDiv]
sub ax, '0'
sub bx, '0'
div bx
add ax, '0'
add dx, '0'
mov [quotient], ax
mov [remainder], dx
mov eax, 4
mov ebx, 1
mov ecx, prompt3
mov edx, prompt3Len
int 80h
mov eax, 4
mov ebx, 1
mov ecx, [quotient]
mov edx, 2
int 80h
mov eax, 4
mov ebx, 1
mov ecx, prompt4
mov edx, prompt4Len
int 80h
mov eax, 4
mov ebx, 1
mov ecx, [remainder]
mov edx, 2
int 80h
jmp exit
exit:
mov eax, 1
xor ebx, ebx
int 80h
如果有人能帮助我理解我做错了什么,我将不胜感激。
【问题讨论】:
-
你输入的是什么数据?
-
@paxdiablo,我测试了它,我的除数是 5,除数是 2
-
@paxdiablo,成功了!谢谢你!然而,使用相同的数据,我得到 1 作为商,3 作为余数。知道为什么吗?
标签: assembly nasm integer-division