Jump to content

Assembler errors

- - - - -

  • Please log in to reply
4 replies to this topic

#1
DarkLordofthePenguins

DarkLordofthePenguins

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 409 posts
I've just copied a program from Assembly Language for Intel-Based Computers. I knew it wouldn't work, but I wanted to see what errors I would get.

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?
Programming is a journey, not a destination.

#2
Gikoskos

Gikoskos

    Newbie

  • Members
  • PipPip
  • 11 posts
I don't have any longterm experience with assembly but a friend of mine does
and he gave me this site :PC Assembly Language
Its a great tutorial to use and also its in a PDF form. Good luck Assemblying.:lol:
Check out this one too :http://homepage.mac.....edu/index.html

#3
DarkLordofthePenguins

DarkLordofthePenguins

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 409 posts
Interestingly enough, I actually found that book on Google just after posting this question. It says it's for NASM and the date is 2006, so it should be pretty helpful. I've started reading it, and so far I find it pretty informative. I'll check out the other link you gave too. Thanks for the suggestions.
Programming is a journey, not a destination.

#4
Gunner

Gunner

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
The irvine stuff should be easily converted to NASM. The source for the macros and library are in: \Irvine32\examples\Lib32 you did grab the samples and source from the publishers site, right? :rolleyes:

#5
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
NASM does accept other directives besides .<directive>

Let's see, the source for MASM is this, right?:
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

Quote

TITLE Add and subtract
I don't think NASM has a TITLE directive; I don't even know what that directive is supposed to do.

Quote

INCLUDE Irvine32.inc
That's supposed to be
%include "Irvine32.inc" 

Quote

main PROC
There's no PROC directive in NASM; instead, you have to use labels; for local labels, you just prepend a dot (.) character before the local label name:
main: 

some code... 

.loop01: 

some more code... 

cmp eax, 20 

jnl .loop01stop 

even more code... 

.loop01stop: 

more stuff... 

ret 

Quote

exit
I don't know what that's supposed to do; return? You could define a macro, named exit, at the beginning of the .asm file, like this:
%macro exit 0-1

	ret %1 

%endmacro 

Quote

main ENDP
NASM doesn't require the programmer to tell when he's done writing a certain function; therefore, there's no directive for that.

Quote

END main
NASM doesn't require the programmer to tell where the file ends, either; also no directive for that.

*****

Well, what I mean, there are directives or whatever they're called that don't have '%' or '.' in them. Like this:
extern MessageBoxA 

extern ExitProcess 


import MessageBoxA user32.dll 

import ExitProcess kernel32.dll 


section .text use32 

..start: 


push dword 0     ;; MB_OK = 0 

push dword the_title 

push dword the_msg 

push dword 0     ;; We do not own a window. 

call [MessageBoxA] 


push dword 0     ;; Exit, returning 0. 

call [ExitProcess] 


section .data 

the_title db "Hello", 0 

the_msg db "Hello World!", 0 


section .bss 

;; We don't really have any not initialized data to reserve space for, this time. 







1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users