flat assembler
Message board for the users of flat assembler.

Index > Main > Does FLAT support typed variables, or not?

Author
Thread Post new topic Reply to topic
Al



Joined: 23 Apr 2006
Posts: 2
Al 23 Apr 2006, 00:30
We use MASM to teach students the basics of assembly programming etc. We use it for years, and it has one significant drawback: no Linux support. Maybe some COFF-->ELF converter would also help a little bit, but we don't know one. A few years ago we tried to switch to NASM, but we decided to stay at MASM, because NASM doesn't support data types at all, which makes the programming really horrible.

In MASM, we can declare a variable
Code:
thevariable dw 0    

...and use it...
Code:
mov thevarible,1    

MASM knows that thevariable is 32 bits, so no additional size specification is required. In NASM, this code doesn't work. The problem is that without this typed variables the code is likely to get very buggy, especially the code made by the beginners.

The question: Is Flat Assembler similar to MASM, or NASM?
Post 23 Apr 2006, 00:30
View user's profile Send private message Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi 23 Apr 2006, 00:57
Code:
testvar dw      0
mov     [testvar], 1    

works just fine Smile

i really suggest reading these:
http://flatassembler.net/docs.php?article=ufasm
and
http://flatassembler.net/docs.php?article=design
should give you good view what Tomasz wants to achieve in fasm
Post 23 Apr 2006, 00:57
View user's profile Send private message MSN Messenger Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost 23 Apr 2006, 03:30
Al wrote:
We use MASM to teach students the basics of assembly programming etc. We use it for years, and it has one significant drawback: no Linux support. Maybe some COFF-->ELF converter would also help a little bit, but we don't know one. A few years ago we tried to switch to NASM, but we decided to stay at MASM, because NASM doesn't support data types at all, which makes the programming really horrible.

In MASM, we can declare a variable
Code:
thevariable dw 0    

...and use it...
Code:
mov thevarible,1    

MASM knows that thevariable is 32 bits, so no additional size specification is required. In NASM, this code doesn't work. The problem is that without this typed variables the code is likely to get very buggy, especially the code made by the beginners.

The question: Is Flat Assembler similar to MASM, or NASM?


dw is "d word" (data, define, can't recall), it is 16bits not 32, and would not be 32bits even under MASM....

the reason
Code:
mov thevarible,1    
does not work in NASM is because under NASM and FASM "thevarible" would reference the address of where the variable is in memory,
Code:
mov [thevarible],1    
would work in NASM and FASM, i suggest reading the NASM documentation, but FASM is much better than NASM

_________________
redghost.ca
Post 23 Apr 2006, 03:30
View user's profile Send private message AIM Address MSN Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 23 Apr 2006, 09:27
The first section of Design Principles is about this topic (among other things).

RedGhost: the point here is that with NASM, even this:
Code:
mov [thevarible],1    

wouldn't assemble (for fasm it is OK though, as fasm remembers that variable was defined with DW).
EVEN WORSE, this:
Code:
mov al,[thevarible]    

would assemble under NASM, even though there's most probably a programmer's mistake here, as 16-bit variable cannot fit in 8-bit register. fasm, just like TASM and MASM, catches this kind of error.
Post 23 Apr 2006, 09:27
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 23 Apr 2006, 09:53
It's really nice that FASM remembers type (or size, whatever Smile ) of variables while still being a low-level assembler. IMHO, not remember variable type/size is plain lazyness from the assembler writers side.

Kudos, Tomasz!
Post 23 Apr 2006, 09:53
View user's profile Send private message Visit poster's website Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost 24 Apr 2006, 06:07
Tomasz Grysztar wrote:
The first section of Design Principles is about this topic (among other things).

RedGhost: the point here is that with NASM, even this:
Code:
mov [thevarible],1    

wouldn't assemble (for fasm it is OK though, as fasm remembers that variable was defined with DW).
EVEN WORSE, this:
Code:
mov al,[thevarible]    

would assemble under NASM, even though there's most probably a programmer's mistake here, as 16-bit variable cannot fit in 8-bit register. fasm, just like TASM and MASM, catches this kind of error.

ah how could i forget having to prefix everything with 'dword' 'word' 'byte' in NASM, made some of the code look ugly imo

_________________
redghost.ca
Post 24 Apr 2006, 06:07
View user's profile Send private message AIM Address MSN Messenger Reply with quote
Al



Joined: 23 Apr 2006
Posts: 2
Al 27 May 2006, 15:11
Sorry for the error in my first post - dw surely is always 16 bits, I just mistyped or something Wink

So Flat Assembler remembers the types (or better said sizes) of variables. That's nice to hear! Very Happy
Post 27 May 2006, 15:11
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.