【已解决】问题 9.asm nasm中的乘法和除法
示例 以下示例将 3 与 2 相乘,并显示结果 −
section .text global _start ;must be declared for using gcc
_start: ;tell linker entry point
mov al,'3' sub al, '0'
mov bl, '2' sub bl, '0' mul bl add al, '0'
mov [res], al 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 eax,1 ;system call number (sys_exit) int 0x80 ;call kernel
section .data
msg db "The result is:", 0xA,0xD
len equ $- msg
segment .bss
res resb 1
当上面的代码被编译并执行时,会产生以下结果 −
The result is: 6
实际上只输出The result is: 然后exit code 1 异常退出了。
已解决 al寄存器存储被存数 结果放在ax中 所以应该 mov [res],ax
''' section .text global _start
_start: mov ax,'8' sub ax,'0'
mov bl,'2' sub bl,'0' div bl add al,byte '0' add ah,byte '0' mov [quotient],al mov [remainder],ah mov edx,1 mov ecx,quotient mov eax,4 mov ebx,1 int 0x80 mov edx,1 mov ecx,remainder mov eax,4 mov ebx,1 int 0x80 mov eax,1 int 0x80section .bss quotient resb 1 remainder resb 1 '''