flat assembler
Message board for the users of flat assembler.

Index > Main > NASM To FASM Conversion

Author
Thread Post new topic Reply to topic
Robert Rayment



Joined: 06 Jul 2004
Posts: 5
Location: Dunstable, UK
Robert Rayment 06 Jul 2004, 09:17
Hi,

It would really get me going if someone could indicate
the FASM syntax for the attached NASM snippet.

I'm familiar with NASM but FASM looks great. I mainly prodiuce
raw code callable from VB and have lots of NASM stuff which I'd
like to convert.

Any other tips on producing raw binary output would be fantastic!

I've found seeking answers fron the FASM docs very complicated.

;NASM FASM

%define ptrMMX64 [ebp-4] ?
%define ptrMC [ebp-8] ?

[bits 32] Use32

; Get absolute address
; to mcode buffer in VB
Call BufferADDR
sub eax,5
; ---

jmp GETOUT

; ---
;
GETOUT:
emms
pop ebx
pop esi
pop edi
mov esp,ebp
pop ebp
ret 16
=====================
; Get mcode buffer
; absolute start address
BufferADDR:
pop eax
push eax
RET
;===========================
ReadMMX64:
mov edi,ptrMMX64
;;
;;
RET

;NASM FASM
; Jump table
[SECTION .data] ?
Sub0 dd PADDB_Demo ?
Sub1 dd PADDW_Demo

Thanks a million in anticipation
Post 06 Jul 2004, 09:17
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 06 Jul 2004, 10:53
Raw binary doesn't use sections, but other than that the following code compiles under the latest version of FASM. I haven't done a disassemble, but it should be ok:

Code:
                               
format binary                                
                                             
ptrMMX64 equ [ebp-4]                         
ptrMC equ [ebp-8]                            
                                             
Use32                                        
                                             
; Get absolute address                       
; to mcode buffer in VB                      
Call BufferADDR                              
sub eax,5                                    
; ---                                        
                                             
jmp GETOUT                                   
                                             
; ---                                        
;                                            
GETOUT:                                      
emms                                         
pop ebx                                      
pop esi                                      
pop edi                                      
mov esp,ebp                                  
pop ebp                                      
ret 16                                       
; =====================                      
; Get mcode buffer                           
; absolute start address                     
BufferADDR:                                  
pop eax                                      
push eax                                     
RET                                          
;===========================                 
ReadMMX64:                                   
mov edi,ptrMMX64                             
;;                                           
;;                                           
RET                                          
                                             
PADDB_Demo: ret          ; Added since this is not defined elsewhere                    
PADDW_Demo: ret         ; As above                              
;NASM FASM                                   
; Jump table                                 
                                             
Sub0 dd PADDB_Demo                           
Sub1 dd PADDW_Demo                           
    


Use format binary to tell FASM to produce raw binary with no headers.

_________________
Charles Childers, Programmer
Post 06 Jul 2004, 10:53
View user's profile Send private message Visit poster's website Reply with quote
Robert Rayment



Joined: 06 Jul 2004
Posts: 5
Location: Dunstable, UK
Robert Rayment 06 Jul 2004, 11:22
Many thanks crc

I successfully converted a NASM asm file to FASM asm & com file
and, though the code was slightly different to NASM bin file,
it ran with the particular VB prog just fine.

Previously I had converted from A386 to NASM
and had the same problem in finding the correct syntax
- sorted out by trial & error! So now you've given me quick
start - thanks again.
Post 06 Jul 2004, 11:22
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 06 Jul 2004, 11:25
Did you find out the differences? There shouldn't be any (maybe only
from size optimizations) because FASM doesn't change your typed
code. Does NASM optimize code?
Post 06 Jul 2004, 11:25
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Robert Rayment



Joined: 06 Jul 2004
Posts: 5
Location: Dunstable, UK
Robert Rayment 06 Jul 2004, 12:09
To Madis731

Example of difference between NASM & FASM binary files

Comparing raw binary files:-
The NASM bin file is 1444 B starting:
E8 43 00 00 00 2D 05 00 00 00 55

The FASM com file is 1435 B starting:
E8 3C 00 00 00 83 E8 05 55

Now I have a List file for NASM showing
addr offsets; hexbytes: mnemonics

But I don't know if FASM can produce such
a List file.

The NASM List files starts:-
17 00000000 E843000000 Call BufferADDR
18 00000005 2D05000000 sub eax,5
19
20 0000000A 55 push ebp


So, not looked into it, but presumably
E8 43 equiv E8 3C and
2D 05 equiv 83 E8

Possibly long & short ways of calc offsets
and size of immediate number.
Post 06 Jul 2004, 12:09
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 06 Jul 2004, 14:07
Well, the things are as I suspected. FASM code is
size optimized and NASM isn't:
Code:
17 00000000 E843000000 Call BufferADDR
18 00000005 2D05000000 sub eax,dword 5
19 0000000A 55 push ebp    

<= as you can see, there are 3 useless bytes after 5
Code:
17 00000000 E83C000000 Call BufferADDR ;Obviously the location of the call changes with code
18 00000005 83E805 sub eax,byte 5
19 00000008 55 push ebp    

That explains why FASM is shorter: it uses shorter forms where possible[/code]

_________________
My updated idol Very Happy http://www.agner.org/optimize/
Post 06 Jul 2004, 14:07
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509 25 Jul 2004, 08:59
The biggest difference that I found between NASM and FASM where local labels and size overrides...

In NASM the following local label is allowed, but in FASM is not:
Code:
label:
  mov eax, 02
.1
  nop
  jmp .1    


but in FASM you need:
Code:
label:
  mov eax, 02
.p1:
  nop
  jmp .p1    


(Notice the letter, as this is needed as FASM will interept .1 as 0.1, and additional the colon)

The other difference, was that if a variable was defined as a word, FASM would complain if you tried to access it as a byte, without a size override. (The same applies for other sizes as well, eg myvar dd 0, and accessed as a word, etc).

Other than that, no differences.
Post 25 Jul 2004, 08:59
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 25 Jul 2004, 12:52
Quote:
(Notice the letter, as this is needed as FASM will interept .1 as 0.1, and additional the colon)


Incomplete floating point numbers should be disallowed since version 1.53. It was causing problems when it was argument of structure.
Post 25 Jul 2004, 12:52
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica 28 Jul 2004, 12:42
yup, iirc and it was names like ".f" and ".e" that cuased some trouble too.
Post 28 Jul 2004, 12:42
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 28 Jul 2004, 19:05
yes, i remember that (i was sending big report about this like probably many others)
Post 28 Jul 2004, 19:05
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.