flat assembler
Message board for the users of flat assembler.

Index > Main > Where to start?

Goto page 1, 2, 3, 4, 5, 6, 7  Next
Author
Thread Post new topic Reply to topic
Inagawa



Joined: 24 Mar 2012
Posts: 153
Inagawa
Hello,

I hate to bother you, but how to learn FASM? I've read "Write Great Code - Volume I", I've also read first 100 or so pages of "Write Great Code - Volume II". Then I started reading "The Art of Assembly Language" (learning HLA is not really my thing), but damn, I feel like I still won't be able to program in FASM after that, will I? It is just so frustrating. I will probably be able to piece together basic assembly instructions, but where am I supposed to learn FASM specific things? The examples are more confusing than helpful.
Could someone point me to literature that would help me? I will honestly spend my time and put my effort into understanding it, but right now I am hindered by the inability to "incrementally program" as I learn (I mean having a sample program in which I test the theory in practice, not to mention the utter lack of tutorials), since I do not know how the FASM program structure should look, what is good practice, what isn't - etc.

Thanks for any help
Post 26 Mar 2012, 18:27
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1412
Location: Toronto, Canada
AsmGuru62
FASM has some code in EXAMPLES folder.

But, generally, just start making some small program and ask questions here as needed.
Post 26 Mar 2012, 18:38
View user's profile Send private message Send e-mail Reply with quote
dancho



Joined: 06 Mar 2011
Posts: 74
dancho
ok , start from here,
basic fasm console program :

Code:
format PE console 5.0
entry cmain
include 'win32axp.inc'

section '.text' code readable executable
cmain:
                            
    invoke ExitProcess,0
                
            
section '.data' data readable writeable
               nop
         
section '.idata' import data readable
 library kernel32,'kernel32.dll'
           
    include 'api\kernel32.inc'
    


write this snipet in fasmw , compile it , read fasm.pdf , all code from here ( except ExitProcess, dont worry about it atm ) is explained there ...

lesson 0.
print 'Hello World' message on the console
Very Happy Very Happy
; little hint /* printf function from msvcrt.dll */

then for lesson 1.
add 2 numbers and print it on the console
Cool
Im sure others forum members will glady give you some more assignments Razz
Post 26 Mar 2012, 19:09
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
lesson 3 create a stealthy key logger. Very Happy

Just kidding.

First I'd recommend learning calling conventions and pointers/structures and addressing.

Once you know those you can move on to different APIs.
Post 26 Mar 2012, 21:50
View user's profile Send private message Reply with quote
Stephen



Joined: 13 Aug 2011
Posts: 30
Stephen
Inagawa wrote:
how to learn FASM?


Windows, Mac, Linux, Dos, Monuet, Dex or things that don't use an OS? What kinds of things do you want to do. Learn some stuff and try writing a few programs that do that. Check out some programs that include source code. I would say look for commented ones, but the uncommented ones are sometimes better. Probably because you have to look more and harder.

Inagawa wrote:
"The Art of Assembly Language" (learning HLA is not really my thing)


I don't think I ever directly used any thing from there. I've gone through the source code and it's very interesting to see how they do things. He also did the ucr assembly library, good stuff but probably totally dated at this point.

Inagawa wrote:
I will probably be able to piece together basic assembly instructions, but where am I supposed to learn FASM specific things?


Take some FASM programs and change some things to get different results.

Inagawa wrote:
I do not know how the FASM program structure should look, what is good practice, what isn't - etc.

That gets down into what kind of programmer you are looking to become. If you are on a team or trying to write programs that are part of something else, it matters.You need to be able to work with what others are doing and they need to be able to work with your stuff. If you are writing stuff on your own or with some friends, rule one: fast, rule two: small. Actually rule 2 is no longer the big deal it use to be. Although when your company wants to sell a million items and the controller with 5k of memory costs fifty cents more then the one with 2k, it still matters.

If you need to learn structure take some classes. Look at the source code to a bunch of programs, most of the ones not put out by big companies break rules or only try to follow rule one, make it work fast.

_________________
!31337 Smile
Post 27 Mar 2012, 03:52
View user's profile Send private message Visit poster's website Reply with quote
majidkamali1370



Joined: 31 Oct 2010
Posts: 50
Location: Iran
majidkamali1370
For low level programming "Art of assembly" is a great book.
Otherwise, if you want to do windows programming, there are lots of masm examples out there. You can convert them to fasm syntax. This is a good programming practice.
Post 27 Mar 2012, 09:30
View user's profile Send private message Send e-mail Yahoo Messenger ICQ Number Reply with quote
Inagawa



Joined: 24 Mar 2012
Posts: 153
Inagawa
Hi there, thanks a lot for all the advice! I will study fasm.pdf and try to use the things in practice with what dancho posted here.

Stephen: Well, I am interested mainly in windows. My ultimate goal is to make a very basic compiler. That seems to be a long way from happening, though.
Post 27 Mar 2012, 11:48
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 559
smiddy
Inagawa wrote:
Stephen: Well, I am interested mainly in windows. My ultimate goal is to make a very basic compiler. That seems to be a long way from happening, though.
Ah, the presence of the steep climb of the learning curve. Smile You can read the sources of the "windows" version for more information on interfacing.
Post 27 Mar 2012, 13:27
View user's profile Send private message Reply with quote
Stephen



Joined: 13 Aug 2011
Posts: 30
Stephen
Windows is probably a bit different then you think. You can do a bunch of math and shift a lot of things around in memory, but for the most part when ever you want something to happen your program has to send a request to windows to do it. How they decided to do that is you push all the data to the stack and then make an api call. The hello world program is a good example. You get all the data in place and then call windows and request it open a window of the type you want and put the text in it. That's a good place to start. With that program you can try out opening all kinds of windows with all kinds of different options. If you want to program windows, besides learning asm, you'll need to learn a lot about the windows api's, because that is the way they want you to request windows do things.
Post 28 Mar 2012, 03:43
View user's profile Send private message Visit poster's website Reply with quote
bubach



Joined: 17 Sep 2004
Posts: 340
Location: Trollhättan, Sweden
bubach
IMO you should start with some .com files, using windows 16-bit dos compatibility for easy learning of fasm and assembly in general. when you're more comfortable with the assembly way of doing things it will be easier to move on to windows gui programming.
Post 28 Mar 2012, 13:13
View user's profile Send private message Reply with quote
Inagawa



Joined: 24 Mar 2012
Posts: 153
Inagawa
Well, I've yet to finish the Fasm.pdf
Post 28 Mar 2012, 13:39
View user's profile Send private message Reply with quote
ProphetOfDoom



Joined: 08 Aug 2008
Posts: 120
Location: UK
ProphetOfDoom
Hullo Inagawa,

I learned 32 bit assembly from the book here: http://www.drpaulcarter.com/pcasm/
It covers, if anything, more than you need to know. One area that is lacking is the coverage of the FPU instructions for which you can look here: http://www.website.masmforum.com/tutorials/fptute/
The latter tutorial isn't very friendly though, and makes stuff look harder than it actually is. Once you understand 32-bit assembly you can make the jump to 64-bit with this brief guide: http://www.x86-64.org/documentation/assembly.html and this document: www.agner.org/optimize/calling_conventions.pdf
Post 28 Mar 2012, 21:13
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4240
Location: 2018
edfed
my advice is to code the hello world in the system coding style you want to code for (linux, windows, dos, boot, etc....)

means, write step by step every little boring code and you'll get the instinct, it helps to code faster. Smile
Post 28 Mar 2012, 22:27
View user's profile Send private message Visit poster's website Reply with quote
LostCoder



Joined: 07 Mar 2012
Posts: 22
LostCoder
A lot of compilers has switch to generate assembly listing. You can write small programs in high level languages, generate it's listing and see what and how compiler does.
Post 29 Mar 2012, 11:03
View user's profile Send private message Reply with quote
Inagawa



Joined: 24 Mar 2012
Posts: 153
Inagawa
Thanks a lot to all you guys for the suggestions. It is so calming to know that there is a strong community around FASM Smile

I will check it out, Prophet; I'll get back to you once I do.
Post 29 Mar 2012, 12:51
View user's profile Send private message Reply with quote
Inagawa



Joined: 24 Mar 2012
Posts: 153
Inagawa
Code:
format PE console 5.0
entry start

include 'win32axp.inc'

;============================================================================
section '.data' data readable writeable

__promptMsg_First       db      'Input a number: ', 0
__promptMsg_Repeat      db      'Input another number: ', 0
__feedbackMsg_Higher    db      'Try higher: ', 0
__feedbackMsg_Lower     db      'Try lower: ', 0

;============================================================================
section '.bss' data readable writeable

__inputVal_1    rd    1
__inputVal_2    rd    1

;============================================================================
section '.text' code readable executable

        start:
          entry     0, 0
          pusha
          ccall     [getchar], eax
          mov       __inputVal_1, eax
          ccall     [printf], __inputVal_1
          ccall     [getchar]
          invoke    ExitProcess, 0

 ;============================================================================
section '.idata' import data readable

        library kernel32,'kernel32.dll',\
                user32, 'user32.dll',\
                msvcrt,'msvcrt.dll'

        include 'api\kernel32.inc'
        include 'api\user32.inc'

        import msvcrt,printf, 'printf',\
               getchar,'_fgetchar'    


What am I doing wrong? I fail to see the problem.. The "undefined symbol start" error whenever anything is wrong is really unhelpful in solving problems
Post 29 Mar 2012, 16:27
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7734
Location: Kraków, Poland
Tomasz Grysztar
Inagawa wrote:
What am I doing wrong? I fail to see the problem.. The "undefined symbol start" error whenever anything is wrong is really unhelpful in solving problems
It appears you have had downloaded one of the recent buggy "experimental" releases of fasm that had this problem - I apologize for letting that happen. Please download 1.69.50 and it should be better.
Post 29 Mar 2012, 17:05
View user's profile Send private message Visit poster's website Reply with quote
Inagawa



Joined: 24 Mar 2012
Posts: 153
Inagawa
Thanks, it finally says where the problem is. Now I can try to fix it myself.

Edit: Shame on me, forgot the brackets on __inputVal_1 Rolling Eyes
Post 29 Mar 2012, 17:17
View user's profile Send private message Reply with quote
Inagawa



Joined: 24 Mar 2012
Posts: 153
Inagawa
I hope I can continue to write here with my obnoxious questions.

How do I print numbers with [printf]? It only prints the ASCII equivalent. I have tried all I could think of but nothing helped me
Post 30 Mar 2012, 16:20
View user's profile Send private message Reply with quote
gunblade



Joined: 19 Feb 2004
Posts: 209
gunblade
printf's syntax is:

printf(format, [param]...);

The way you are using it at the moment, is just passing it a string as a "format", which it just prints out..
So.. printf("hello"); would print hello, and printf(__inputVal_1); would print the string in the inputval variable.

If you want to print numbers/etc, you need to use the parameters. The "format" string doesnt just need to be text, it can also contain replacable strings, usually using % to specify that it is a special word.
Theres a big list of all the available formats.. but lets take "string" first..

printf("%s",__inputVal_1) would be the same as printf(__inputVal_1)..

For your numbers, you then have to start using other characters.. so, theres %u for "unsigned integer", which is probably what you want..
printf("%u",5) would print 5 (notice that 5 isnt a string like "5", its just the number), you can then also just pass a variable with a number in it, like: printf("%u",numberVal);

You could also pass __inputVal_1 like in the program above, but then it will end up printing the pointer to the string as an unsigned integer.
One of the many available pages describing printf's syntax: (with examples at the bottom):

http://www.cplusplus.com/reference/clibrary/cstdio/printf/

You would do the same, just call it using ccall [printf],format,parameter,parameter2,parameter3....

I can write up a quick working example if you cant get it working, but would be good for you to write one yourself (just dont forget those brackets again Wink)
Post 30 Mar 2012, 16:33
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2, 3, 4, 5, 6, 7  Next

< 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 YouTube, Twitter.

Website powered by rwasa.