Here's the code:
TITLE Add and subtract ; This program adds and subtracts 32-bit integers. INCLUDE Irvine32.inc .code main PROC mov eax,10000h ; EAX = 10000h add eax,40000h ; EAS = 40000h sub eax,20000h ; EAX = 30000h call DumpRegs ; display registers exit main ENDP END main
Here are the error messages:
add.s:1: error: expression syntax error add.s:5: error: parser: instruction expected add.s:7: error: parser: instruction expected add.s:14: error: symbol `main' redefined add.s:14: error: parser: instruction expected add.s:15: error: parser: instruction expected
Okay, here's the thing: My book is written for the MASM assembler on the IA-32 architecture. I am using NASM on an x86-64 architecture. Since this is a simple program and probably doesn't use any IA-32-specific components, compatibility between CPU architectures shouldn't be an issue. The real issue, I think, is with the assembler.
This program uses the assembler directives TITLE, INCLUDE, ENDP, and END, which may or may not be MASM-specific. It also uses DumpRegs, which I'm guessing is a Windows or DOS system call (I'm using Mac OS X).
Here's my assessment of the errors: The assembler said "instruction expected" for lines that contained assembler directives not beginning with a dot, so I'm guessing that NASM only recognizes dot directives like .code. The "expression syntax error" occurred when I used "add" (a reserved word) in the first line. MASM would interpret it as some sort of comment, given the MASM-specific directive TITLE, while NASM, which doesn't recognize TITLE, interprets TITLE it as a label for the ADD instruction. I don't understand the part about "main" being redefined, though. Is main a reserved word or something?
I'm going to keep reading my book, because I think it gives a good idea of how the x86 architecture works, but I need another tutorial to go along with it. Can you recommend any good NASM tutorials?


Sign In
Create Account


Back to top









