Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

FASM $ keyword

Name: Anonymous 2011-06-02 21:42

It is my understanding that the $ keyword in FASM is equal to the current location during assembling, and in fact on http://en.wikibooks.org/wiki/X86_Assembly/FASM_Syntax the following example is given:

mystring           db    "This is my string", 0
mystring.length    equ   $-mystring

However, when placing two of these blocks back to back, I get wildly unexpected results:

a          db 'Hello, world! A'
alength    equ $ - a
b          db 'Hello, world! B'
blength    equ $ - b

alength now equals 30, whiles blength equals 20. Expected result is 15 for both.

Anybody know what could be happening?

Name: Anonymous 2011-06-02 21:46

LOL LACK OF NULL TERMINATION

Name: Anonymous 2011-06-02 21:48

Actually, just after posting this thread (even though I was trying to figure out the problem for around 3 hours before resorting to this), I managed to figure it out.

It seems like the equ directive now actually inserts its value at the place where it's used, and that position is used for calculation - so if I used alength later on in the code, it was actually using that position for its $ calculation.

Changing the code to this fixes it:

a          db 'Hello, world! A'
alength    db $ - a
b          db 'Hello, world! B'
blength    db $ - b

but requires me to use [alength], and is now actually treated as a memory address instead of a precompiler constant.

Name: Anonymous 2011-06-02 21:50

>>2
Waste of a byte...

Name: Anonymous 2011-06-02 21:55

>>3
Oh, it seems my manual was outdated.

The new syntax is

alength = ($ - a) and works fine

Name: Anonymous 2011-06-03 0:19

Use NASM instead.

Don't change these.
Name: Email:
Entire Thread Thread List