flat assembler
Message board for the users of flat assembler.

Index > Linux > FASM Tutorial for Linux?

Author
Thread Post new topic Reply to topic
Octal



Joined: 06 Aug 2009
Posts: 4
Location: South Carolina
Octal
I'm not new to assembly, but I am new to FASM. I found a really good tutorial under the Documentation section of this website, but quickly found out that it was for DOS machines. Any suggestions?

_________________
Version: 3.12
GCS/IT d-(--) s>+:>- a15 c++(+++)>++++$ UL++>++++$ P>+++ L++>++++$ E? W+++>$
N?>++ o? K- w-- O? M V? PS PE+ Y-- PGP- t>++ 5? X R+>+++$ tv++ b+() DI+++ D++
G++>++++ e- h! r>+++ y>+++
Post 06 Aug 2009, 11:02
View user's profile Send private message Send e-mail Reply with quote
rCX



Joined: 29 Jul 2007
Posts: 166
Location: Maryland, USA
rCX
I'm sort of a newbie at linux asm as well. I don't know if any fasm tutorials for linux exist Sad I found a nasm tutorial which was fairly helpful.
Post 06 Aug 2009, 22:51
View user's profile Send private message Reply with quote
Octal



Joined: 06 Aug 2009
Posts: 4
Location: South Carolina
Octal
Thanks. Although I'd hate to betray FASM, I'll try it out.

Thanks again.
-Brandon
Post 07 Aug 2009, 02:08
View user's profile Send private message Send e-mail Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
Don't consider it deserting FASM, but more like helping Smile
TASM, NASM are closely related to FASM so you won't lose that much.
Post 07 Aug 2009, 06:48
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
rCX



Joined: 29 Jul 2007
Posts: 166
Location: Maryland, USA
rCX
It wouldn't be impossible for someone (with Tomasz's permission, of course) to rewrite the DOS tutorial for linux. Wouldn't it be a matter of replacing int 21h examples with int 80h ones?
Post 07 Aug 2009, 19:28
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]
Post 07 Aug 2009, 19:36
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
if the same functions are mounted to the same numbers, it shouldn't be a problem. However, though i have never programmed for DOS, i don't see that as very likely. It's very difficult to start out with anything other than windows with fasm unless you're willing to use ld by command line and learn the order of params before you seriously code. Lots of amd64 examples, though that are readily assemblable in the examples section to help with using them. =) Just a matter of assembling your hello world then using man. If you've used fasm for anything else, not a problem. but, if you're new to fasm, i would recommend taking to programming for windows using wine until you get used to the fasm syntax if you're used to programming for windows as using a different assembler (why learn 2 new things at once if you can learn 2 things seperately?).
Post 17 Aug 2009, 23:45
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
There are some good examples in the FreeBSD developer's handbook:

http://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/x86.html

Hope that helps
Post 20 Aug 2009, 14:50
View user's profile Send private message Reply with quote
Endre



Joined: 29 Dec 2003
Posts: 212
Location: Budapest, Hungary
Endre
By the way kohlrak is right. Fasm is not as great success on Linux (on other non windows systems even less) as it is on windows. It's really a pain to debug your code (even 64-bit) generated by fasm (absolutely no debug info). Its preprocessor capabilities have been designed with windows in mind. On Unix systems you mostly don't need to use as sophisticated macros (except if you want something fasm doesn't provide by default) as on windows. On Unices however there are infinite header files with infinite times infinite constants that you'd like to use without the necessity of tracking them down to their bare values that then you'd have to hard-code in your program (just look at the Linux examples, hard coded magic values everywhere, terrible). The other assemblers (nasm, yasm, etc.) may be better choice (even when it's about debugging), but I don't use them either. I simply use the gnu assembler (gas, as). It's part of the gnu compiler infrastructure that is defacto standard on the most popular Unix systems (Linux, BSDs, Mac), but it can also be found on the others (Windows, Solaris, AIX, etc.) as well. And it works with the c-preprocessor automatically and seamlessly. So if you are once used to it then you won't have any problems with other systems. You don't need to invoke gnu-ld or gnu-as directly, but of course you have to know some options, but it should not be a problem. As an example here the little hello world linux example for powerpc (I just compile it with the gnu powerpc cross-compiler and run it with qemu-ppc on my intel machine Smile.
Code:
/**
 * Compile it with command:
 * powerpc-pc-linux-gnu-gcc -s -nostdlib -mregnames hello.S -o hello
 *
 * On non PowerPC run it with qemu in user mode:
 * qemu-ppc ./hello
 */

        .if 0
#include <asm/unistd.h>
#include <unistd.h>
        .endif

        .line __LINE__
        .globl _start
        .text
_start:
        li      r0, __NR_write
        li      r3, STDOUT_FILENO
        li      r4, msg@l
        oris    r4, r4, msg@h
        li      r5, msg_len
        sc
        li      r0, __NR_exit
        li      r3, 0
        sc

msg:
        .ascii "Hello 32-bit PowerPC world!\n"
msg_len = . - msg    
The intel program looks almost exactly the same except the mnemonics between the labels _start and msg. And here the fasm code of the same powerpc program for the case you don't want to install the cross compiler (qemu you will still need):
Code:
db 0x7F, 0x45, 0x4C, 0x46, 0x01, 0x02, 0x01, 0x00
db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
db 0x00, 0x02, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01
db 0x10, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x34
db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
db 0x00, 0x34, 0x00, 0x20, 0x00, 0x02, 0x00, 0x00
db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
db 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00
db 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAD
db 0x00, 0x00, 0x00, 0xAD, 0x00, 0x00, 0x00, 0x05
db 0x00, 0x01, 0x00, 0x00, 0x65, 0x04, 0x15, 0x80
db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00
db 0x00, 0x00, 0x00, 0x04, 0x38, 0x00, 0x00, 0x04
db 0x38, 0x60, 0x00, 0x01, 0x38, 0x80, 0x00, 0x98
db 0x3C, 0x84, 0x10, 0x00, 0x38, 0xA0, 0x00, 0x15
db 0x44, 0x00, 0x00, 0x02, 0x38, 0x00, 0x00, 0x01
db 0x38, 0x60, 0x00, 0x00, 0x44, 0x00, 0x00, 0x02
db 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x50, 0x6F
db 0x77, 0x65, 0x72, 0x50, 0x43, 0x20, 0x77, 0x6F
db 0x72, 0x6C, 0x64, 0x21, 0x0A    

It's maybe a little bit OFF and seems a gnu advocacy, but I just wanted to demonstrate you that on Unix systems you mostly need constants from headers but not macros overwhelming everything. And if you are used to an assembler (actually to a compiler infrastructure) then you're not lost on other systems/platforms (e.g. if you want to write some complicated calculations to your super computer consisted of some PS3s, or just want to learn another assembly. Qemu can emulate quite a few processors Smile).
Post 22 Aug 2009, 20: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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.