flat assembler
Message board for the users of flat assembler.

Index > Windows > Tutorial?

Author
Thread Post new topic Reply to topic
null1024



Joined: 07 Jan 2008
Posts: 4
null1024
Hello, I am an absolute n00b at programming, I found FASM, and fell in love with how much less intimidating the syntax was compared to C/C++. And the speed bonus of assembly also interested me. What I'm looking for is a tutorial on basic Win32 API usage in FASM. I've been looking around for 2 days, and what I've found was either too shallow (it only got up to how to display a message box or console output -- nothing about setting up a window and putting stuff in it), or not for FASM (the only decent one was for MASM, and even though I found the code samples converted for FASM, the text was confusing to work with in FASM, as that wasn't converted)

tl;dr
Other than the tutorials listed, are there any tutorials on how to use the Win32 API in FASM (i.e. teach the Win32 API)? I've tried adapting C/C++ tutorials, and I have no luck, as the syntaxes are too different for me to figure out how to convert.

_________________
I suck at coding.
Post 09 Jan 2008, 01:33
View user's profile Send private message Reply with quote
zxcv
Guest




zxcv
Thres no good tutorial for this, at least i didnt found any.
win32 api use only cdecl and stdcall, and can be imported from libraries like:
kernel32.dll - basic, functions that access memory, processes, threadas, etc.
ws2_32.dll - network.
msvcrt.dll - strings and data managment. Functions like strstr, malloc.

note that all libs except msvcrt are stdcall (function removes arguments from stack, so if u wana call it twice u have to push them again, stdcall save arguments). Registers ebx, esi, ebp and edi are constant.
Post 09 Jan 2008, 10:08
Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
1) The hard way - search the forum for CreateWindowEx

2) Easier way - try my included package of collected interesting stuff
Sometimes slow: http://www.tud.ttu.ee/~t060429/Up/Package.7z
Array is the easiest to start from (but its without a CreateWindow command).
Sometimes the samples are so old that they do not even compile Razz well
work for the reader.

3) Somewhat easy is to look around Projects section of this forum and download some er... projects. I might suggest:
- Calculator
- Mandelbrot
- Alarm
- Digital Clock
- Sudoku
- Analog Clock
and some mine:
- Conversion Dialog (message handling, redraw, keyb. input, etc.)
- Electro (everupdating package of the schematic drawing/simulating thingy)


Description: Included: loading binary image in the window (BIN2BMP), drawing bubbles (CHEM), Schematics drawing and interaction with mouse (ELECTRO), Draw lines and interact w/ mouse (JOON), Gravity (PALL), Text output and mouse (ROBOT), The ant algo that works only o
Download
Filename: Package.7z
Filesize: 88.74 KB
Downloaded: 52 Time(s)


_________________
My updated idol Very Happy http://www.agner.org/optimize/
Post 09 Jan 2008, 10:54
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
lol your link of "azillionmonkeys" has a lot of very slow algo's... My Euclidean algo takes only 7 lines of assembly (like three are moves and two are spent on the jcc), his ASCII conversion technique is extremely stupid because u just need to add a constant to each byte!! Sry, but duhh. Some other algo's I found there (actually, a lot), including StrLen functions and others are way too big! Most of them that I looked at I have implemented in under ten lines, the StrLen function is usually in-lined by compilers and is not nearly as long as the one his comp. inserted. Wow, don't use that site Smile.
Post 10 Jan 2008, 04:48
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3055
Location: vpcmipstrm
bitRAKE
Some people will not agree with me, but here is how I started programming in assembler and it worked (but that isn't proof of anything):

1. Get yourself a debugger. I recommend OllyDbg. Just load any program into it, and start changing stuff and writing code. You can do this by double-clicking on a line. The cool part is how there is no gap between writing and executing code - you type something and see how it works right then. If you break something just quit OllyDbg or restart windows - it is really rare that any real damage could be done (backups are a good thing).

2. Read the PSDK - nothing like hearing it from the horses mouth. Yeah, the examples are in C++, but you are going to learn how to read that too. You'll be able to link the source examples on the board here and the PSDK text fairly easy before long.

Things will go wrong so get comfortable with OllyDbg/(debugger) and how code looks there verses your source file. Comrade has a patched version of FASMW that puts OllyDbg one keystroke away.

This is the fastest way to get jump started, really. Pick some simple little proggies to code through: like a bouncing ball, or gadget to help the kids use the computer - like a timer to shut down the browser! Twisted Evil (Working on your homework? - damn straight you are!)
Post 10 Jan 2008, 05:47
View user's profile Send private message Visit poster's website Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
@AlexP: How is LOC relative to speed? The site is about speed, not codesize Neutral Lets benchmark your Euclidean! Are you sure it works on EVERY CPU equally well?
Because modern CPUs are "backward-optimization-compatible" meaning that faster Core 2 code works faster on P4, III, II etc. So if your algorithm really is faster today - we can help this site to keep on updating.

Actually I conducted some tests:
Code:
Compiler and switches used:
E:\>icl /Ox /QxT /Qip /Qvec-report3 GCD.c
Intel(R) C++ Compiler for applications running on Intel(R) 64, Version 10.0    Build 20070809 Package ID: W_CC_C_10.0.027

Results:

E:\>GCD.exe
1,92703853
Input values were: 1, 92703853
Timers:
        Naive  - 667319496
        Modern - 785205048
        BINGCD - 848798508
        VilleM - 468
Result values: a=1, b=1, c=1, d=1

E:\>GCD.exe
10,1000000000
Input values were: 10, 1000000000
Timers:
        Naive  - 719499768
        Modern - 865184016
        BINGCD - 915700596
        VilleM - 408
Result values: a=10, b=10, c=10, d=10

E:\>GCD.exe
832648,38745
Input values were: 832648, 38745
Timers:
        Naive  - 2628
        Modern - 3084
        BINGCD - 3084
        VilleM - 1200
Result values: a=1, b=1, c=1, d=

E:\>GCD.exe
0,0
Input values were: 0, 0
Timers:
        Naive  - 600
        Modern - 216
        BINGCD - 180
        VilleM - 168
Result values: a=1, b=1, c=1, d=0 ;!!!!!
    

Last one seems to be inconsistent with other three ^o) why?

And yes - debugging is a way to go too. I totally forgot about that. After OllyDBG, get yourself known to FDBG (Feryno Debugger) too if you're going to write for 64-bit OSs Win64/Linux64.
But we ware that debugging threaded applications is very bad. If you're talking about Creating a Window then already there are message loops that are threaded so OllyDBG doesn't work as smoothly as for programs without a window.
Post 10 Jan 2008, 07:11
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3055
Location: vpcmipstrm
bitRAKE
Code:
; Extended Euclid's algorithm
; non-recursive version, from Knuth ACP vol. 2, pg. 302 section 5.5.2 Algorithm X
; return:
; GCD(eax,edx) = ECX = A*EAX + B*EDX
; ECX unsigned; EAX,EDX signed
eGCD:       pushad
      mov esi,0               ; u1
        mov edi,1               ; v1
        mov dword [esp+28],1    ; u
 mov dword [esp+20],0    ; v
 jmp .x

.0:   div ebp
     mov ebx,esi
 mov ecx,edi
 xchg [esp+28],esi
   xchg [esp+20],edi
   imul ebx,eax
        imul ecx,eax
        sub esi,ebx
 sub edi,ecx
 mov eax,ebp
.x:  mov ebp,edx
 test edx,edx
        mov edx,0
   jne .0
      mov [esp+24],eax
    popad
       retn    
Just a conversion from Knuth, not too much effort to optimize.
Post 10 Jan 2008, 10:04
View user's profile Send private message Visit poster's website Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
You can go to my website for some windows/directx examples. Just click on the [www] at the bottom of this post to get there. If you want to re-compile the examples, just follow the directions posted on the website.
Post 10 Jan 2008, 10:59
View user's profile Send private message Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
Here's my Euclidean algo - It uses div on every loop so it's probably pretty slow like u said Smile
Code:
        pusha
        xor edx,edx
        mov eax,[Lower]
        mov ebx,[Higher]
        ;Euclidean Algo
    @@: div ebx
        cmp edx,0
        je @f
        mov eax,ebx
        mov ebx,edx
        xor edx,edx
        jmp @b
        ;Print the GCD to console
    @@: push ebx [Higher] [Lower] GCD
        call [printf]
        add esp,16
        popa
        push 0
        call [ExitProcess]
    

I just like that it's seven lines, three of which are devoted to cmp/jmp. The StrLen function that I have seen a C compiler output is this:
Code:
       lea esi,ds:[eax+1]
@@: mov cl,ds[eax]
       add eax,1
       test cl,cl
       jnz short (@b)
      sub eax,esi
    

I used a fasm version of this code in a command-line parser function a whie back:
Code:
      lea ebx,[Message+1]
@@: mov cl,[eax]
      inc eax
      test cl,cl
      jnz @b
      sub eax,ebx
    

I still haven't worked on the extended euclidean, I should do that now... Have fun learning FASM~
Post 11 Jan 2008, 14:15
View user's profile Send private message Visit poster's website 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.