示例 以下示例将 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


"当两个字节相乘时 − 被乘数在AL寄存器中,乘数是内存中或另一个寄存器中的一个字节。 乘积在 AX 中。 乘积的高8位存放在AH中,低8位存放在AL中。" 2024-08-29T06:07:06.png "当两个单字值相乘时 −被乘数应该在AX寄存器中,乘数是内存或另一个寄存器中的一个字。 例如,对于像MUL CX这样的指令,您必须将乘数存储在CX中,将被乘数存储在AX中。生成的结果是一个双字,需要两个寄存器。 高位(最左边)部分存储在 DX 中,低位(最右边)部分存储在 AX 中。" 2024-08-29T06:07:21.png "当两个双字值相乘时−当两个双字值相乘时,被乘数应位于 EAX 中,乘数是存储在内存或另一个寄存器中的双字值。 生成的乘积存储在 EDX:EAX 寄存器中,即高位 32 位存储在 EDX 寄存器中,低位 32 位存储在 EAX 寄存器中。" 2024-08-29T06:07:28.png

2024-08-29T06:14:46.png

标签: none

仅有一条评论

  1. ''' 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 0x80

    section .bss quotient resb 1 remainder resb 1 '''

添加新评论