我正在学习本教程 (http://www.tutorialspoint.com/assembly_programming/assembly_arithmetic_instructions.htm) 并写下这段代码。我喜欢打印两者,商和余数,但我没有得到理想的结果。
这是代码:
section .text
global _start
_start:
mov al,9
mov bl,2
div bl
mov bl, al
add bl, byte '0'
mov [res], byte bl
mov bl, ah
add bl, byte '0'
mov [tm], byte bl
mov ecx,msg
mov edx, len
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov ecx,res
mov edx,1
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov ecx,msg2
mov edx,len2
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov ecx,tm
mov edx,1
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
msg db "The result is:", 0xA,0xD
len equ $- msg
msg2 db 0xA,0xD,"Remainder is:", 0xA,0xD
len2 equ $- msg
segment .bss
tm resb 1
res resb 1
结果:
The result is:
4
Remainder is:
141%
知道什么是错的?
答案 0 :(得分:-1)
%宏打印2 mov eax,4 mov ebx,1 mov ecx,%1 mov edx,%2 int 80h %endmacro
%宏读取2
mov eax,3
mov ebx,2
mov ecx,%1
mov edx,%2
int 80h
%endmacro
部分.data
userMsg db'请输入一个数字:'
lenUserMsg equ $ -userMsg
usermsg1 db'输入第二个数字:'
lenusermsg1 equ $ -usermsg1
商数db'商是:'
quotientlength equ $ -quotient
余数db'余数是:'
remaininglength equ $ -remainder
len EQU 16
部分.bss;未初始化的数据 n resb len n1 resb len
qtnt resb len r resb len
section .text;代码段 全球_开始 _start:
print userMsg,lenUserMsg 读n,len print usermsg1,lenusermsg1 读n1,len
mov al,[n] sub al,' 0'
mov bl,[n1] sub bl,' 0'
div bl 添加al,' 0' 添加dl,' 0' mov [qtnt],al
打印商,quotientlength print qtnt,len
mov [r],dl
print remaining,remainderlength print r,len
退出: mov eax,1 mov ebx,0 int 80h