flat assembler
Message board for the users of flat assembler.

Index > Main > Converting from NASM to FASM, help required!

Author
Thread Post new topic Reply to topic
SomeoneNew



Joined: 12 Aug 2006
Posts: 54
SomeoneNew
Hi guys, I'm attempting to convert from NASM to FASM but I'm new to both so... there you go, I'm stuck since the beginning; Would anybody here be able to help me out on this one?

First, the macros; heres one from NASM:

Code:
%macro getbitM 0
    add    dx, dx
    jnz    short %%stillbitsleft
    mov    dx, [esi]
    lea    esi, [esi + 2]
    adc    dx, dx
  %%stillbitsleft:
%endmacro    


How would I go about converting this one to FASM?

Secondly, is this the same in both assemblers?

NASM:
Code:
jae    near .donedepacking    

Code:
 jnc    short .literal    


What does "near" and "short" mean?, what are they?.


Thanks!

_________________
Im new, sorry if I bothered with any stupid question Smile
Post 02 Dec 2007, 05:04
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin
A short is a unsigned WORD or SWORD..

near address
A memory location specified by the offset from the start of the value in a segment register. A near address requires only 2 bytes.


macro getbitM 0
add dx, dx
jnz stillbitsleft ;jump if not zero
mov dx, [esi]
lea esi, [esi + 2]
adc dx, dx
stillbitsleft:
endmacro

as for the rest it should be fine- if not look under the macro section..
I don't use macros...I am not sure if the macro getbitM 0 needs to be mod.. Very Happy
Post 02 Dec 2007, 05:27
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
Code:
; I'm suppossing that the "0" is a typo
macro getbitM
{
; I'm assuming that a label that starts with %% is local to the macro. 
; I added two dots to not affect the scope of possible surrounding labels

local ..stillbitsleft 
    add    dx, dx 
    jnz    short ..stillbitsleft 
    mov    dx, [esi] 
    lea    esi, [esi + 2] 
    adc    dx, dx 
  ..stillbitsleft: 
}
    


short is to ensure that the offset will be short (1 byte), and near just specifies that the operand is an offset only so there will be no changes at CS register. http://flatassembler.net/docs.php?article=manual#1.2.5

If you know NASM already I suggest reading the fasm manual anyway since the syntax shares some aspects with NASM but is not 100 % compatible.
Post 02 Dec 2007, 05:30
View user's profile Send private message Reply with quote
SomeoneNew



Joined: 12 Aug 2006
Posts: 54
SomeoneNew
Thanks, I ported the entire code now and it compiles just fine but I don't have a way to try it out.


I have 2 problems

1) I don't know how to use file io in FASM, how can I read the contents of a file to memory and how can I write the contents of a memory area to a file? - I'm under Windows by the way.

2) How can I convert a "flat" source (ie no procedures, just labels) to a routine / proc ?

Any procedure examples would be great, I just need to return 1 variable.
Post 02 Dec 2007, 05:50
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
I don't know how to use file io in FASM, how can I read the contents of a file to memory and how can I write the contents of a memory area to a file? - I'm under Windows by the way.

many ways:
Win32API - CreateFile(), ReadFile(), WriteFile()
libc (msvcrt.dll) - fopen(), fread(), fwrite()
FASMLIB

Quote:
How can I convert a "flat" source (ie no procedures, just labels) to a routine / proc ?

best way is with "proc" macro - review FASM documentation of win32 headers (click "documentation" on FASM site)
Post 02 Dec 2007, 10:44
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number 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. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.