flat assembler
Message board for the users of flat assembler.

Index > Main > what are some good FASM tutorials...for beginner?

Author
Thread Post new topic Reply to topic
yj1214



Joined: 09 Aug 2015
Posts: 3
yj1214
Hello guys, i'm a typical C++ programmer with some experiences with OpenGL, GLFW, Irrlicht, Panda3D etc. So you could say that i'm pretty decent at programming.

Anyway, I wanted to learn something more challenging and very OS related...So I decided to learn Assembly. But I noticed that there are lots of NASM tutorials but not FASM...

So i'm here to ask you guys what are some good FASM tutorials...for beginner.

_________________
Assembly Level: Newb
C++ Level: Decent
C Level: Pretty Good
Python Level: Pretty Good
Post 09 Aug 2015, 19:17
View user's profile Send private message Reply with quote
Trinitek



Joined: 06 Nov 2011
Posts: 257
Trinitek
NASM syntax will assemble in FASM, but the %directives are not compatible. Swap them for the FASM equivalents and most files will work fine.
Post 09 Aug 2015, 20:06
View user's profile Send private message Reply with quote
yj1214



Joined: 09 Aug 2015
Posts: 3
yj1214
This is Hello World assembly code from NASM tutorial.

Code:
section .text
    global _start   ;must be declared for linker (ld)
_start:             ;tells linker entry point
    mov edx,len     ;message length
    mov ecx,msg     ;message to write
    mov ebx,1       ;file descriptor (stdout)
    mov eax,4       ;system call number (sys_write)
    int 0x80        ;call kernel
        
    mov eax,1       ;system call number (sys_exit)
    int 0x80        ;call kernel

section .data
msg db 'Hello, world!', 0xa  ;our dear string
len equ $ - msg     ;length of our dear string
    


When I compile this code using FASM, it gives me an error that says,

Code:
section .text
error: illegal instruction.
    
Post 09 Aug 2015, 20:18
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 671
system error
Welcome to fasm

1) you don't need a linker in your particular case. Just compile it using ./fasm yourfile.asm and execute it just like that. Since you don't need a linker, you dont need global or _start or section

2) Hence..

Code:
format elf executable

segment readable executable;section .text 
    mov edx,len     ;message length 
    mov ecx,msg     ;message to write 
    mov ebx,1       ;file descriptor (stdout) 
    mov eax,4       ;system call number (sys_write) 
    int 0x80        ;call kernel 
         
    mov eax,1       ;system call number (sys_exit) 
    int 0x80        ;call kernel 

segment readable writeable 
msg db 'Hello, world!', 0xa  ;our dear string 
len = $ - msg     ;length of our dear string     
Post 09 Aug 2015, 21:03
View user's profile Send private message Reply with quote
yj1214



Joined: 09 Aug 2015
Posts: 3
yj1214
Thanks for the answer but now i'm getting an "error: undefined symbol 'len'." error...
Post 09 Aug 2015, 21:13
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 671
system error
Look carefully...
Post 09 Aug 2015, 21:15
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17621
Location: In your JS exploiting you and your system
revolution
The fasm download already has example "hello world" programs. Look in the folder named "examples".
Post 10 Aug 2015, 02:57
View user's profile Send private message Visit poster's website Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
yj1214 wrote:
Thanks for the answer but now i'm getting an "error: undefined symbol 'len'." error...

Code:
len=... vs len EQU    


Code:
msg db 'Hello, world!', 0xa  ;our dear string
.len =$ - msg     ;length of our dear string

msg2 db 'What ?', 0xa  ;our dear string
.len =$ - msg2     ;length of our dear string

msg3 db 'Aha, aha, aha !', 0xa  ;our dear string
.len =$ - msg3     ;length of our dear string
    


This way you can always get the size with msgx.len and don't need to take new variable names.
Post 10 Aug 2015, 12:06
View user's profile Send private message Send e-mail 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.