我目前正在参加装配课程,我必须在Mac OS X上运行代码,而且我对如何在Mac OS X上运行代码感到迷失
以下是代码:
; Description: This program adds and subtracts 16‐bit integers.
; Revision Date:
INCLUDE Irvine32.inc
.code
main PROC
mov ax, 650 ; AX = 650h
sub ax, 50h ; AX = 600h
sub ax, 100h ; AX = 500h
sub ax, 300h ; AX = 200h
call DumpRegs ; display registers
exit
main ENDP
END main
这是我收到的错误消息
Tayvions-MacBook-Pro:~ tayvionpayton$ cd Documents/Code/
Tayvions-MacBook-Pro:Code tayvionpayton$ nasm -f macho32 -o0 assembly_Tp.asm
assembly_Tp.asm:4: error: parser: instruction expected
assembly_Tp.asm:5: warning: label alone on a line without a colon might be in error
assembly_Tp.asm:6: error: parser: instruction expected
assembly_Tp.asm:12: warning: label alone on a line without a colon might be in error
assembly_Tp.asm:13: error: symbol `main' redefined
assembly_Tp.asm:13: error: parser: instruction expected
assembly_Tp.asm:14: error: parser: instruction expected
Tayvions-MacBook-Pro:Code tayvionpayton$
答案 0 :(得分:1)
汇编程序代码未运行,它是:
gnu
汇编程序,在使用所谓的AT&T Syntax
语法编写源代码时使用。见GAS。gnu
链接器[LD]。3 以下是使用NASM的两步编译/链接示例:
首先将源代码编译为目标文件。这个例子是32位:
nasm -f macho32 -O0 helloworld.asm
这将生成helloworld.o
(对象)文件。然后,您需要通过链接完成此操作:
ld helloworld.o -o helloworld
您现在可以使用./helloworld