flat assembler
Message board for the users of flat assembler.

Index > Main > Three small questions !

Author
Thread Post new topic Reply to topic
majidkamali1370



Joined: 31 Oct 2010
Posts: 50
Location: Iran
majidkamali1370
Hi.
I have three small questions. Excuse me that they are not related to each other.

1. Is it better to create macros, or labels for modular programming as procedures? (I don't want to use Windows macros)

2. Is it a good work to use pusha and popa at beginning and end of my every procedures? (do they effect speed very much?)

3. What is difference between reserving data (with Rx) and defining data (with Dx)? I mean what is the benefit of reserving data when we could use this:
Code:
byteData db ?    


Thanks a lot Smile
Post 29 Nov 2011, 22:40
View user's profile Send private message Send e-mail Yahoo Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
2. Yes, they affect performance quite a bit, better save what you actually modify but additionally establish a convention in which some registers are allowed to be trashed by procedures like most existing calling conventions do.

3. But with Rx you can say the amount of space to reserve (e.g. byteArray rb 4096), while your example reserve only one unit of the data type size. An appropriate equivalent would be "byteArray 4096 dup(?)" (although I'm not sure if there is some subtle difference with rb), but fasm will compile rb faster.
Post 29 Nov 2011, 22:52
View user's profile Send private message Reply with quote
khatch



Joined: 24 Oct 2011
Posts: 68
khatch
Hi!
well i think macro is for frequently writing like this in include/macro/proc32.inc :

macro invoke proc,[arg] ; indirectly call STDCALL procedure
{ common
if ~ arg eq
reverse
pushd arg
common
end if
call [proc] }

this well make your writing the program easy than you write this every time you call a function

pushd arg
call [proc]

like hello.exe in examples in the fasmw*.zip
which wrote in hello.asm :

invoke ExitProcess,0

which analyzed to :

pushd 0
call [Exitprocess]


finally i am beginner programmer in assembly language !!!!!
Post 30 Nov 2011, 01:27
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1409
Location: Toronto, Canada
AsmGuru62
I do not understand the question #1.
Personally, I use simple macros (not overly complex) just to shorten my code and make it more readable. I even have 1-line macros, like the ones I use to work with my local variables:
Code:
macro LocSet var, value
{
     mov     [ebp + var], value
}
macro LocAddr reg, var
{
    lea     reg, [ebp + var]
}
macro LocMove dest, src
{
     push    [ebp + src]
 pop     [ebp + dest]
}
...
       LocSet  loc1.ofsData, esi
   LocSet  loc1.loopCounter, 32
        LocMove loc1.pObject2, loc1.pObject1
        LocAddr edi, loc1.vectHandles
    

And since my IDE has auto-complete - the "loc1." type of thing shows a list of members.
Or macros for branching:
Code:
macro IfEqu reg, target
{
  cmp     reg, value
  je      target
}
...
     IfEqu   eax,    WM_CREATE,      .OnCreate
   IfEqu   eax,    WM_DESTROY,     .OnDestroy
  IfEqu   eax,    WM_CHAR,        .OnChar
    

Just to fit more code into a glance and make it more readable in the future.
Post 30 Nov 2011, 15:33
View user's profile Send private message Send e-mail Reply with quote
khatch



Joined: 24 Oct 2011
Posts: 68
khatch
Hi AsmGuru62
are you sure from your last example because i got this error while assembled it :

flat assembler version 1.69.32 (498586 kilobytes memory)
main.asm [7]:
IfEqu eax, WM_CREATE, .OnCreate
error: invalid macro arguments.

and thanks for learning the beginners(which i one of them) Wink

_________________
Jesus Christ is our Savior
Post 30 Nov 2011, 16:18
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1409
Location: Toronto, Canada
AsmGuru62
yep, I missed the 'value' in macro definition - was writing from memory!
Smile
It must be:
Code:
macro IfEqu reg, value, target   ; <-- 'value' was missing!
{
...
}
    
Post 30 Nov 2011, 17:53
View user's profile Send private message Send e-mail Reply with quote
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr
majidkamali1370 wrote:
Hi.

2. Is it a good work to use pusha and popa at beginning and end of my every procedures? (do they effect speed very much?)



Set up a benchmark test


Code:
    stdcall test1
    stdcall test2
    int3

proc test1
    pushad
    xor ecx, ecx
  @@:
    push ecx
    ; do something here
    pop ecx
    loop @b
    popad
    ret
endp

proc test2
    push ebx edi esi
    xor ecx, ecx
  @@:
    push ecx
    ; do same thing here
    pop ecx
    loop @b
    pop esi edi ebx
    ret
endp

    


Set up a timer for the two procs. If you find no difference, you're not doing much in your proc.

magicĀ²
Post 01 Dec 2011, 00:46
View user's profile Send private message Reply with quote
majidkamali1370



Joined: 31 Oct 2010
Posts: 50
Location: Iran
majidkamali1370
How to create a timer in assembly?
Post 01 Dec 2011, 00:51
View user's profile Send private message Send e-mail Yahoo Messenger ICQ Number Reply with quote
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr
majidkamali1370 wrote:
How to create a timer in assembly?


Simplest is
Code:
    invoke    GetTickCount
    push       eax
    .
    do your stuff
    .
    invoke    GetTickCount
    pop        ebx
    sub        eax, ebx
    

eax is number of milliseconds taken.
Post 01 Dec 2011, 08:20
View user's profile Send private message Reply with quote
majidkamali1370



Joined: 31 Oct 2010
Posts: 50
Location: Iran
majidkamali1370
Thank you guys Wink
Post 01 Dec 2011, 09:57
View user's profile Send private message Send e-mail Yahoo Messenger ICQ Number 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.