NASM - The Netwide Assembler
NASM Forum => Example Code => Topic started by: spongefreddie on August 30, 2017, 02:31:28 AM
-
Hi,
I'm brand new to assembly, and I'm using Jeff Duntemann's "Assembly Language Step-by-Step" as my first text book. I'm running Manjaro 17.0 Cinnamon (kernel 4.9.44-1-MANJARO). I've installed NASM as the book suggested, and that all worked fine. I'm not new to Linux, so no terminal issues.
The problem is I encountered an "expression syntax error" in the very first sample program. The debugger indicated that this was the offending line (line 3):
EatMsg: db “Eat at Joe’s!“,10
I've been doing a lot of searching and found one page where someone was asking a similar question and the person who answered said something about NASM changing from the time Duntemann wrote his first edition. I'm using the 3rd edition.
I was just wondering if anyone could explain what's wrong with his code, because I sure couldn't say at this point in my assembly education. Here's the full program:
SECTION .data
EatMsg: db “Eat at Joe’s!“,10
EatLen: equ $-EatMsg
SECTION .bss
SECTION .text
global _start
_start:
nop
mov eax,4
mov ebx,1
mov ecx,EatMsg
mov edx,EatLen
int 80H
mov eax,1
mov ebx,0
int 80H
Any help would be much appreciated, thank you. I'm a bit discouraged that the very first program's syntax isn't correct.
sf
-
Hi spongefreddie,
Welcome to the Forum.
I didn't/don't see anything wrong with your/Jeff's code. However... when I tried to copy it to try it myself, I got notification about unicode characters! The quote characters, both double and single, are showing up as question marks! So... I think there's some issue with the editor you're using? See if you can find an option to force ASCII text. You can delete and overwrite the quote marks - that worked here - but you don't want to have to do that with every example!
If you continue to have problems, get back to us!
Best,
Frank
P.S. If you put the word "code" in square brackets "[]" at the start of your code, and "/code" at the end, you'll get "code tags" which make the code easier to read(?) and definitely easier to cut-and-paste. Normally, I would do that for you, but since this seems "odd" I wanted to leave it just as it is...
-
Just for fun, since I was fooling with the quote marks anyway, I thought I'd demonstrate a fairly recent capability of Nasm. If we use "back quotes", Nasm will interpret C-style escape sequences...
SECTION .data
EatMsg: db `Eat at Joe's!\n`
EatLen: equ $-EatMsg
SECTION .bss
SECTION .text
global _start
_start:
nop
mov eax,4
mov ebx,1
mov ecx,EatMsg
mov edx,EatLen
int 80H
mov eax,1
mov ebx,0
int 80H
We could use `\0` to indicate a zero-terminated string, too, but we don't need it here. This is just an alternative - it isn't "better" unless you prefer it, in which case perhaps it is...
Best,
Frank
-
Frank, thanks!!! Unicode characters... I totally didn't even think about that. The command line debugger didn't mention them specifically, but now in retrospect, obviously that's what the syntax error was. I produced the object file with no errors once I overwrote the characters as you suggested. I also did the single quote apostrophe for good measure. That's what I get for copy/pasting code from a PDF file, lol.
It's quite a load off to get my confidence back that my textbook isn't a pile of dung. I was, and still am, really excited to finally learn assembly. ;) I taught myself C a few years ago with Prata's Primer Plus (4th edition), along with a few trips to cprogramming.com, so I'm sure at some point I'll be back here for more ASM advice.
By the way, thanks for the escape sequence info. That's the sort of cool knowledge I have grown used to acquiring from programmer's forums. :)
Regards,
sf