Noob对ASM可能是一个愚蠢的错误,但我似乎无法在任何地方找到解决方案。 我试图通过EBX划分EDX:EAX并显示商,但每当我运行它时,我总是在EAX寄存器中获得1而不管数字(只要它们是正数)。
SYS_EXIT equ 1
SYS_READ equ 3
SYS_WRITE equ 4
STD_IN equ 0
STD_OUT equ 1
section .data
msg1 db 'Enter first number:', 0xA, 0xD
len1 equ $ - msg1
msg2 db 'Enter divisor:', 0xA, 0xD
len2 equ $ - msg2
msg3 db 'Result: '
len3 equ $ - msg3
msg4 db ' ', 0xA, 0xD
len4 equ $ - msg4
section .bss
num1 resb 2
num2 resb 2
res resb 2
section .text
global _start
_start:
mov eax, SYS_WRITE
mov ebx, STD_OUT
mov ecx, msg1
mov edx, len1
int 0x80
mov eax, SYS_READ
mov ebx, STD_IN
mov ecx, num1
mov edx, 2
int 0x80
mov eax, SYS_WRITE
mov ebx, STD_OUT
mov ecx, msg2
mov edx, len2
int 0x80
mov eax, SYS_READ
mov ebx, STD_IN
mov ecx, num2
mov edx, 2
int 0x80
mov eax, SYS_WRITE
mov ebx, STD_OUT
mov ecx, msg3
mov edx, len3
int 0x80
xor edx, edx
mov eax, [num1]
cdq
mov ebx, [num2]
div ebx
add eax, byte 48
mov [res], eax
int 0x80
mov eax, SYS_WRITE
mov ebx, STD_OUT
mov ecx, res
mov edx, 2
int 0x80
mov eax, SYS_WRITE
mov ebx, STD_OUT
mov ecx, msg4
mov edx, len4
int 0x80
mov eax, SYS_EXIT
int 0x80