flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > HLL macros

Author
Thread Post new topic Reply to topic
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
I was thinking, for me FASM is the greatest assembler in this world! Because it do what tell it to do. I learned ASM by myself with trial and error because FASM has good syntax and is easy to use. After learning DOS ASM I moved to Win32 ASM, and now I'm happy with RadAsm+FASM.
But I think people usually change from FASM to MASM32 because of the HLL macros like .IF, .WHILE, etc... I think FASM should come with pre-built in HLL macros.

I'm happy with FASM because I do:

Code:
format PE GUI 4.0
include '%fasminc%\win32a.inc'
start:
invoke MessageBox,0,msg,ttl,0
ret

msg db 'Hi!',0
ttl db 'FASM is fun!',0

data import
library user32,'user32.dll'
import user32,\
MessageBox,'MessageBoxA'
end data
    

and I get a tiny 1024 bytes app that shows a MessageBox! Very Happy

But when I need to do something like:
Code:
proc DlgProc,hWnd,uMsg,wParam,lParam
        enter   
        push edi esi ebx
        
        mov eax,[uMsg]
        cmp     eax,WM_COMMAND
        je      jCOMMAND
        cmp     eax,WM_INITDIALOG
        je      jINITDIALOG
        cmp     eax,WM_CLOSE
        je      jCLOSE
        xor eax,eax
        jmp finish

jINITDIALOG:
        mov eax,[hWnd]
        mov [gWnd],eax
        
        mov eax,1
        jmp finish
        
jCOMMAND:
        mov eax,[wParam]
        cmp     eax,1000
        je      a1000
        xor eax,eax
        jmp finish
        
a1000:
        invoke SendMessage,[hWnd],WM_CLOSE,0,0
        mov eax,1
        jmp finish
        
jCLOSE: 
        invoke EndDialog,[hWnd],0
        mov eax,1
        
finish:
        pop ebx esi edi
        return
endp
    

it's a pain to take care of all those cmp's and je's. It is handy with macros like .IF and .SWITCH.

I think you know what I mean.
Please share your opinion.

Thanks!
Post 25 Apr 2005, 20:58
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7715
Location: Kraków, Poland
Tomasz Grysztar
Have you tried the standard ".if" macro that is provided with the fasmw's includes? With the old method of including (which you used in your sample above), you can get it with:
Code:
include '%fasminc%\macro\if.inc'    

And when you use WIN32AX/WIN32WX or WIN32AXP/WIN32WXP includes, it is included by default.

The syntaxes are like:
Code:
.if eax,e,4 ; if eax equal to 4
; some code
.elseif eax,ge,7 ; if eax greater or equal to 5
; some code
.elseif ebx ; if ebx is not 0
; some code
.endif

.while [var],b,1000 ; while [var] is below 1000
; some code
.endw

.repeat
; some code
.until eax ; until eax is not 0    
Post 25 Apr 2005, 22:43
View user's profile Send private message Visit poster's website Reply with quote
Octavio



Joined: 21 Jun 2003
Posts: 366
Location: Spain
Octavio
OzzY wrote:
But I think people usually change from FASM to MASM32 because of the HLL macros like .IF, .WHILE, etc...
I don´t understand why they change to masm instead of Basic or C. C not only has a better implementation of 'if while' ,it also optimizes the code.

Quote:

I think FASM should come with pre-built in HLL macros.

For programing in HLL is better to use a HLL .
Quote:

it's a pain to take care of all those cmp's and je's. It is handy with macros like .IF and .SWITCH.
I think you know what I mean.

Yes , you mean that you don´t like assembly because is not like C.
Post 25 Apr 2005, 23:28
View user's profile Send private message Visit poster's website Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
Octavio: I prefer asm, but sometimes I need rapid app develop with the power of asm. And I know that C compilers of today are very optimized. Under windows C can produce 1024 bytes exe with a good linker. But I like the power of asm.

Privalov: Thanks a lot! FASM is great! And the macro capability of Fasm is just perfect!! Very Happy
I tested and it works very good:
Code:
format PE GUI 4.0
include '%fasminc%\win32a.inc'
include '%fasminc%\macro\if.inc'
start:

invoke MessageBox,0,msg,ttl,MB_YESNO
.if eax,e,IDYES
    invoke MessageBox,0,answer,ttl,0
.else
    mov esi,answer
    .while byte[esi],ne,'Y'
       inc esi
    .endw
    mov word[esi],'No'
    add esi,2
    mov byte[esi],0
    invoke MessageBox,0,answer,ttl,0
.endif
ret

msg db 'Yes or no?',0
ttl db 'HLL macros test with fasm',0
answer db 'Answer: Yes',0

data import
library user32,'user32'
include '%fasminc%\apia\user32.inc'
end data
    

Everytime I ask on this board I'm more happy with Fasm! =)
Thanks!
Post 26 Apr 2005, 01:01
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
OzzY: By the time, you will learn to code not structured code (with .if, .while), but what i call "linear code", where you have (kind-of) independent blocks of code linked with jumps. Right now i have problems coding structured code, because you just can't use it to create "natural" solution for program flow, you have to workaround everything. (For example here:
Code:
for a=1 to 10
{
  for b=1 to 10
  {
    ... <part1>
    if something
      goto OutOfLoop
    ... <part2>
  }
}
OutOfLoop:
    

In "proper" structured code you have to emulate end-conditions (a:=10, b:=10) instead of goto, and put rest of code (<part2>) under another if, which really just messes the code. But try to say it to some structured-code purist, he will tell you that "your concept is wrong" and it will result in completely different conditions on loop as it was meant for. This was just an example, both coding styles have pluses and minuses, you will learn by yourself.
Post 26 Apr 2005, 09:39
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
vid wrote:
OzzY: By the time, you will learn to code not structured code (with .if, .while), but what i call "linear code", where you have (kind-of) independent blocks of code linked with jumps.


IMHO, more precise definition is:

Structured programming is not "block based" programming, neither if..then..while..etc. HLL operators.
Structured programming is beyond all these syntax conventions. It is a way of thinking and methods of program design. You can write unstructured program in Pascal or C and highly structured program in pure assembler or even HEX. And I don't think "if..then" is more readable or more structured than "cmp jcc" - all is a matter of habits.

Regards.
Post 26 Apr 2005, 11:25
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo
and large and nested if..then blocks are less readable/maintainable and more error prone.
Post 26 Apr 2005, 12:38
View user's profile Send private message Yahoo Messenger 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.

Powered by rwasa.