flat assembler
Message board for the users of flat assembler.

Index > Windows > [Question from a Newbie] : Proc

Author
Thread Post new topic Reply to topic
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith
Hi everybody

i'm learning asm actually (well i try)
i found a little prog here about arrays and i decided to modify it with a procedure.

here it is

Code:
format PE GUI 4.0
entry start

include '%fasminc%\win32a.inc'

section '.data' data readable writeable

_caption db 'Test array',0

_simple_array:
cat     db 'cat',0
dog     db 'dog',0
dolphin db 'dolhpin',0
monkey  db 'monkey',0
donkey  db 'donkey',0
pig     db 'pig',0
end_array db 0,0

_pointer2array dd cat,dog,dolphin,monkey,donkey,pig  ;0->cat; 5->pig

section '.code' code readable executable
start:
    stdcall Aff_Element,0
    stdcall Aff_Element,5
    invoke  ExitProcess,0
ret

proc Aff_Element, numElement
    push    ebx esi edi
    mov     edi,[numElement]  ;  <---which element
    shl     edi,2
    invoke  MessageBox,0,[_pointer2array+edi],_caption,0      ; show me-> _simple_array[2]
    pop     ebx esi edi
endp

section '.idata' import data readable writeable

    library kernel32, 'KERNEL32.DLL',\
            user32,   'USER32.DLL'

    include '%fasminc%\apia\kernel32.inc'
    include '%fasminc%\apia\user32.inc'
    


Pb is, after the first call to aff_element, i've got a error message, i don't know why, help welcome Confused

_________________
Je suis sur de 'rien', mais je ne suis pas sur du 'tout'.
Post 03 May 2005, 14:31
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7724
Location: Kraków, Poland
Tomasz Grysztar
1) You forgot to return from your procedure, it should be done with the "return" macro.

2) When you restore registers from stack, you have to pop them in the reverse order, since you first get the register that is on the top of the stack and this is the last one you pushed there.

So the correct procedure should look like:
Code:
proc Aff_Element, numElement
    push    ebx esi edi
    mov     edi,[numElement]
    shl     edi,2
    invoke  MessageBox,0,[_pointer2array+edi],_caption,0
    pop     edi esi ebx
    return
endp    


BTW, because of your problem I have realized it would be not bad thing to make "endp" macro generate return code on the end of procedure automatically when you forget to do it. I will think about it.
Post 03 May 2005, 15:07
View user's profile Send private message Visit poster's website Reply with quote
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith
thank you SO much Very Happy
Post 03 May 2005, 15:55
View user's profile Send private message Visit poster's website Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
Quote:
Code:
    mov     edi,[numElement]
    shl     edi,2
    invoke  MessageBox,0,[_pointer2array+edi],_caption,0     

Actually it could be done like this:
Code:
    mov     edi,[numElement]
    invoke  MessageBox,0,[_pointer2array+edi*4],_caption,0     

If you multiply by 2,4,8,16,... you can do like this
Post 03 May 2005, 20:28
View user's profile Send private message Visit poster's website Reply with quote
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith
thank you Wink
Post 03 May 2005, 21:12
View user's profile Send private message Visit poster's website Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld
Reverend wrote:
If you multiply by 2,4,8,16,... you can do like this
AFAIK, it can be only 1,2,3,4,5,8 and 9 Wink like follows:
Code:
  [eax*1] = [eax]
  [eax*2] = [eax*2] = [eax+eax]
  [eax*3] = [eax*2+eax]
  [eax*4] = [eax*4]
  [eax*5] = [eax*4+eax]
  [eax*8] = [eax*8]
  [eax*9] = [eax*8+eax]    
Post 04 May 2005, 22:06
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
shouldn't you have an "enter" before the "proc" because of the parameter? Also someone made the "return" macro except a return-value, I can post the new macro if you like.
madmatt
Post 05 May 2005, 07:23
View user's profile Send private message Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld
ENTER as macro should be used only if you have some local variables, otherwise it doesn't generate any code.
Post 05 May 2005, 07:53
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
mike.dld wrote:
Reverend wrote:
If you multiply by 2,4,8,16,... you can do like this
AFAIK, it can be only 1,2,3,4,5,8 and 9 Wink like follows:
Yes, you're right, sorry for my mistake Embarassed
Post 05 May 2005, 20:20
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
mike.dld: Didn't know you could do that. Tried it in a simple test and it seemed to work.
MadMatt
Post 05 May 2005, 20:58
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.

Powered by rwasa.