我不理解乘法代码周围的寄存器值
I'm not understanding register values surrounding multiplication code
我一直在使用学习 NASM 汇编的 tutorialspoint 指南自学汇编,但是在尝试编写将两个用户输入的数字相乘的代码时,我 运行 遇到了一些问题。我 运行 犯了错误,我认为这也可能是一个没有完全理解汇编架构如何在寄存器、堆栈和数据段方面工作的问题。如果我能得到帮助,首先了解是什么导致了我的代码中的错误,然后找到资源以更好地掌握 nasm 程序集,我将不胜感激。
这是我的代码:
write equ 4
read equ 3
stdout equ 1
stdin equ 0
section .text
global _start
_start:
mov eax, write
mov ebx, stdout
mov ecx, msg1
mov edx, len1
int 80h
mov eax, read
mov ebx, stdin
mov ecx, num1
mov edx, 2
int 80h
mov eax, write
mov ebx, stdout
mov ecx, msg2
mov edx, len2
int 80h
mov eax, read
mov ebx, stdin
mov ecx, num2
mov edx, 2
int 80h
mov al, num1
mov dl, num2
imul dl
mov [res], al
mov eax, write
mov ebx, stdout
mov ecx, res
mov edx, 4
int 80h
mov eax, 1
int 80h
section .bss
num1 resb 2
num2 resb 2
res resb 4
section .data
msg1 db "Please input your first value: "
len1 equ $-msg1
msg2 db "Please input your second value: "
len2 equ $-msg2
这是我收到的错误:
main.o: In function `_start':
main.asm:(.text+0x59): relocation truncated to fit: R_386_8 against `.bss'
main.asm:(.text+0x5b): relocation truncated to fit: R_386_8 against `.bss'
我也尝试过使用 mul
代替 imul
。谢谢。
代码
mov al, num1
mov dl, num2
imul dl
表示将num1的地址移动到al中,将num2的地址移动到dl中。错误是因为这些变量的地址不适合 8 位寄存器。
您真正想要做的是移动值:
mov al, [num1]
mov dl, [num2]
我一直在使用学习 NASM 汇编的 tutorialspoint 指南自学汇编,但是在尝试编写将两个用户输入的数字相乘的代码时,我 运行 遇到了一些问题。我 运行 犯了错误,我认为这也可能是一个没有完全理解汇编架构如何在寄存器、堆栈和数据段方面工作的问题。如果我能得到帮助,首先了解是什么导致了我的代码中的错误,然后找到资源以更好地掌握 nasm 程序集,我将不胜感激。
这是我的代码:
write equ 4
read equ 3
stdout equ 1
stdin equ 0
section .text
global _start
_start:
mov eax, write
mov ebx, stdout
mov ecx, msg1
mov edx, len1
int 80h
mov eax, read
mov ebx, stdin
mov ecx, num1
mov edx, 2
int 80h
mov eax, write
mov ebx, stdout
mov ecx, msg2
mov edx, len2
int 80h
mov eax, read
mov ebx, stdin
mov ecx, num2
mov edx, 2
int 80h
mov al, num1
mov dl, num2
imul dl
mov [res], al
mov eax, write
mov ebx, stdout
mov ecx, res
mov edx, 4
int 80h
mov eax, 1
int 80h
section .bss
num1 resb 2
num2 resb 2
res resb 4
section .data
msg1 db "Please input your first value: "
len1 equ $-msg1
msg2 db "Please input your second value: "
len2 equ $-msg2
这是我收到的错误:
main.o: In function `_start':
main.asm:(.text+0x59): relocation truncated to fit: R_386_8 against `.bss'
main.asm:(.text+0x5b): relocation truncated to fit: R_386_8 against `.bss'
我也尝试过使用 mul
代替 imul
。谢谢。
代码
mov al, num1
mov dl, num2
imul dl
表示将num1的地址移动到al中,将num2的地址移动到dl中。错误是因为这些变量的地址不适合 8 位寄存器。
您真正想要做的是移动值:
mov al, [num1]
mov dl, [num2]