Assembly NASM中的打印商与余数
我正在学习这个教程 () 然后写下这段代码。我喜欢同时打印商和余数,但是我没有得到想要的结果 代码如下:Assembly NASM中的打印商与余数,assembly,nasm,division,Assembly,Nasm,Division,我正在学习这个教程 () 然后写下这段代码。我喜欢同时打印商和余数,但是我没有得到想要的结果 代码如下: 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
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%
知道怎么回事吗?%macro print 2
mov-eax,4
mov-ebx,1
mov ecx,%1
移动edx,%2
int 80h
%endmacro
%宏读取2
mov-eax,3
mov-ebx,2
mov ecx,%1
移动edx,%2int 80h %endmacro 章节.数据
userMsg db'请输入一个数字:' lenUserMsg eq$-userMsg
usermsg1 db'输入第二个数字:' lenusermsg1 eq$-usermsg1 商db’商是:' 商长等于$-商
余数db'余数为:' 余数长度等于$-余数
len EQU 16 第三节bss;未初始化数据 n resb len n1 resb len qtnt resb len 雷斯伯伦酒店 第节.案文;代码段 全局启动
_开始: 打印userMsg,lenUserMsg 读n,len 打印用户msg1,lenusermsg1 读n1,len mov al[n] sub al,'0' mov bl,[n1] 分界区,“0” bl分区 加上“0” 添加dl,“0” mov[qtnt],al 印刷商 打印qtnt,len mov[r],dl 打印余数,余数长度 列侬 出口: mov-eax,1 mov-ebx,0
int 80h不应该是
len2 eq$-msg2
(注意msg后面的2)?天哪!你完全正确!谢谢,请先看这个:还有