flat assembler
Message board for the users of flat assembler.

Index > Main > Short Newbie Qestions (about macros, imports & syntax)

Author
Thread Post new topic Reply to topic
flat_user



Joined: 01 Jun 2010
Posts: 13
flat_user
Hi there,
I'm considering to start using FASM and so I'm actually checking it out.
But since there's something I wonder about and I also would like to maintain some syntax-features of the previous assembler I have some questions regarding FASM:

1. How to simplify importing?
I guess you have to specify every single import manually since FASM isn't a linker but just writes those into the import table but I'm just wondering if there's an easier way...

2. Can I somehow decide inside of a macro if a given argument is a self defined proc/label or if it is a label defined in the imports?
I want to have a macro which automatically appends brackets for imports..

3. Would it be possible to enable parsing 'mov [byte eax],10h' instead of/additional to 'mov byte [eax],10h?

Thank you! Very Happy
Post 01 Jun 2010, 18:46
View user's profile Send private message Reply with quote
Trojany



Joined: 31 May 2010
Posts: 5
Trojany
hi,
1.: depends on which format you want to you produce with your assembly:
for example if you want to make PE files linking to the WinAPI, you can use the default include files:
Code:
include 'win32wx.inc'

main:
invoke MessageBox, 0, 'Message', 'Caption', 0
invoke ExitProcess, 0
.end main    
imports are done for you by included files.

2.: you could define a local label like ".isAPI" when modifying the import macro. this label could be checked from other macros.

for 3. I don't know - although I bet it could be done by preprocessing as well

EDIT:
This is some example code for what I said about number 2:
Code:
include 'win32wx.inc'

macro myimp library, [name, string]
{
  name#.isAPI = 1
}

macro import library, [functions]
{
  common
    import library, functions
    myimp library, functions
}

main:
invoke MessageBox, 0, 'Message', 'Caption', 0
invoke ExitProcess, 0
.end main

if defined MessageBoxW.isAPI
  display 'MessageBoxW is API!', 10
else
  display 'MessageBoxW is not API!', 10
end if

if defined main.isAPI
  display 'main is API!', 10
else
  display 'main is not API!', 10
end if    
Post 01 Jun 2010, 21:31
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
flat_user wrote:
…since FASM isn't a linker…
Compile to COFF and use external linker. GoLink don't even need import libraries.
flat_user wrote:
3. Would it be possible to enable parsing 'mov [byte eax],10h' instead of/additional to 'mov byte [eax],10h?
Well, let's see:
  • [eax] could be byte (or word / dword / etc. as it's memory reference);
  • eax is always dword (and addressing mode with byte registers is unavailable, except implicit in xlatb).
What will be the purpose of such illogical syntax?
Post 02 Jun 2010, 06:00
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17260
Location: In your JS exploiting you and your system
revolution
baldr wrote:
What will be the purpose of such illogical syntax?
It is the MASM influence. It seems some people want to make fasm into a MASM clone Confused
Post 02 Jun 2010, 06:28
View user's profile Send private message Visit poster's website Reply with quote
flat_user



Joined: 01 Jun 2010
Posts: 13
flat_user
Actually it's TASM, also read FASM's design principles
I don't think it's illogical as it means 'take a byte from this address'
FASM's syntax actually is taken from TASM with the little change that the size modifier is written outside of the brackets.
Also FASM is capable of parsing MASM's syntax which is 'mov byte ptr eax,10h', so I guess you'd say it already is a MASM clone?
Post 02 Jun 2010, 13:37
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17260
Location: In your JS exploiting you and your system
revolution
Hmm, let's see.

byte eax ----> al (since al would be the byte truncation of eax)

[byte eax] ----> [al] (but we still don't know the size of data to read from address at al)

Yep, makes perfect sense to me. Not! Razz
Post 02 Jun 2010, 13:58
View user's profile Send private message Visit poster's website Reply with quote
flat_user



Joined: 01 Jun 2010
Posts: 13
flat_user
Kind of childish, but if you're enjoying such a discussion...
Also if you want to cast something (like byte eax == al), better stick to C++
Post 02 Jun 2010, 14:24
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
flat_user,

mov byte ptr word 0, 0 and mov byte ptr dword 0, 0 have sense, mov byte ptr byte eax, 0 doesn't.
Type qualifier outside square brackets tells the size of operand, inside — size of address. No matter where FASM get this from.

If you don't want to troll, show your arguments.
Post 02 Jun 2010, 16:49
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Just for reference sake:
Code:
format pe gui 4.0

mov byte ptr word 0, 0
mov byte ptr 0, 0
mov byte ptr dword 0, 0
mov byte ptr eax, 0

nop
nop
nop

mov byte [word 0], 0
mov byte [0], 0
mov byte [dword 0], 0
mov byte [eax], 0    
IDA output when put in Borland TASM in Ideal mode:
Code:
.flat:00401000 start:
.flat:00401000                 mov     [byte ptr ds:0], 0
.flat:00401006                 mov     [large byte ptr ds:0], 0
.flat:0040100D                 mov     [large byte ptr ds:0], 0
.flat:00401014                 mov     [byte ptr eax], 0
.flat:00401017                 nop
.flat:00401018                 nop
.flat:00401019                 nop
.flat:0040101A                 mov     [byte ptr ds:0], 0
.flat:00401020                 mov     [large byte ptr ds:0], 0
.flat:00401027                 mov     [large byte ptr ds:0], 0
.flat:0040102E                 mov     [byte ptr eax], 0    
Post 02 Jun 2010, 17:49
View user's profile Send private message Reply with quote
flat_user



Joined: 01 Jun 2010
Posts: 13
flat_user
baldr,
I didn't know FASM would let one specify the size of absolute addresses to adjust the opcode.

Hence I wasn't arguing from the same point of view as I thought FASM wouldn't interpret such syntax at all.
So I was just asking if one could use macros to enable such syntax as TASM uses it.
But as said I didn't know that this syntax is already used for something different in FASM, so that you're pointing out this syntax would interfere with others and thus would be illogical.
Post 02 Jun 2010, 20:15
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
I have seen the MASM address mode syntax, and I find it outright wrong.
Post 02 Jun 2010, 22:19
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
flat_user,

OK, I've understood your point. Almost everything about FASM is in the manual: this is explained in 1.2.6 Size settings subchapter.
Post 03 Jun 2010, 05:19
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17260
Location: In your JS exploiting you and your system
revolution
In MASM you specify the address size in a different place, in a segment block I think. And there is no way to then specify the address size at the individual instruction. Thus the data size is the only possible specifier at the instruction level and things like [byte address] became common (and ugly to say the least).

In fasm we can specify both the address and data sizes separately. mov data_size[address_size address],value becomes possible. So things like [byte address] make no sense at all since you can't address memory with a byte sized address.
Post 03 Jun 2010, 07:31
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17260
Location: In your JS exploiting you and your system
revolution
flat_user wrote:
FASM's syntax actually is taken from TASM with the little change that the size modifier is written outside of the brackets.
Not quite. fasm is based upon TASM's ideal syntax. TASM also supports MASM syntax which is a whole different thing.
flat_user wrote:
Also FASM is capable of parsing MASM's syntax which is 'mov byte ptr eax,10h', so I guess you'd say it already is a MASM clone?
Try to think of ptr as a replacement for the square brackets, [], then it all becomes a bit more sensible.
Post 03 Jun 2010, 07:38
View user's profile Send private message Visit poster's website 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-2020, Tomasz Grysztar.

Powered by rwasa.