【发布时间】:2019-12-10 11:11:49
【问题描述】:
这是我的第一个汇编程序。
任何人都可以帮助使其成功运行。
我看到下面的编译错误。
为什么它无法识别? 和@data?
我正在尝试在程序集中交换两个变量。
我正在执行以下命令
nasm -f elf swap.asm
但我收到此错误:
swap.asm:6: error: symbol `?' undefined
swap.asm:12: error: symbol `@data' undefined
swap.asm:15: error: invalid combination of opcode and operands
swap.asm:21: error: invalid combination of opcode and operands
swap.asm:22: error: invalid combination of opcode and operands
这是我的代码:
section .data
C equ 15
var1 db 12
section .bss
var2 db ?
section .code
global _start
_start:
mov ax, @data
mov ds, ax
mov var2, C
; swap var1 and var2
mov al, var1
mov bl, var2
mov var2, al
mov var1, bl
; now print the swapped values
mov eax, 4 ; 4 = sys_write
mov ebx, 1 ; 1 - std out FD
mov ecx, var1
mov edx, 8
int 80h
mov eax, 4 ; 4 = sys_write
mov ebx, 1 ; 1 - std out FD
mov ecx, var2
mov edx, 8
int 80h
; exit the program
mov eax, 1 ; 1 = sys_exit
mov ebx, 0
int 80h
【问题讨论】:
-
你有 16 位代码和 32 位代码的混合体,其中一些代码是 MASM 语法,其余的是 NASM。
-
我认为对于以下两条指令,操作数的大小不同。应该是什么解决方案,我应该使用 cl 而不是 ecx 吗? mov ecx, var1 mov ecx, var2