flat assembler
Message board for the users of flat assembler.

Index > Main > proc macro problem

Author
Thread Post new topic Reply to topic
snifit



Joined: 10 Dec 2004
Posts: 12
Location: Sweden
snifit 19 Jan 2005, 12:57
I'm trying to do my own proc that has one parameter with the size of a byte.
Depending on the value of that byte the procedure makes different things.

Code:
proc theproc,byteparam
  ; do something
  return
endp    


I can't use the invoke macro since that would use 'call [theproc]' which wouldn't work so i tried to push the parameter myself and then call the proc:

Code:
push onebyte
call theproc    


This does not work either because (my guess) the proc macro doesn't know that it should pop a byte for the "byteparam" parameter.

So I'm wondering if there is some way to do this when using the proc macro?
If not, how should I do?

Code:
  push $
  jmp myownproc
  ; ...

myownproc:
  ; Do something
  pop eax
  ; Add something to eax so I jump to the correct place after the push
  jmp eax    
Post 19 Jan 2005, 12:57
View user's profile Send private message Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix 19 Jan 2005, 13:50
Snifit, let me tell what i know about it. It is not a good idea to put 1 byte to stack because it becomes unaligned.
About your words "This does not work either because (my guess) the proc macro doesn't know that it should pop a byte...". Proc macro doesn't do any pop. You can try this:

myownproc:

byteparam equ ebp+8

push ebp
mov ebp,esp

mov al,[byteparam] ; read passed parameter
; ...
mov esp,ebp
pop ebp
retn 1

When you can call it in this way:

xor eax,eax
or al,[byteparam]
stdcall myownproc,eax

Stdcall is invoke analog, but it make 'call myownproc'.

Regards.
Post 19 Jan 2005, 13:50
View user's profile Send private message Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix 19 Jan 2005, 14:12
Sorry, small mistake: i used 'retn 1' to return from function and had to pass only one byte ('push byte byteparam' instead of using eax)! For my stdcall example at the end of the function must be 'retn 4'.

_________________
Flat Assembler is the best!
Post 19 Jan 2005, 14:12
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 19 Jan 2005, 14:15
AFAIK, you never can push one byte using the instruction "push". You can push word or dword only. The only way to push only one byte is to store it in the stack with "mov" instruction and to decrement esp by 1.
Post 19 Jan 2005, 14:15
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
snifit



Joined: 10 Dec 2004
Posts: 12
Location: Sweden
snifit 19 Jan 2005, 14:37
Big thanks guys!
I didn't realize it was such a problem with a single byte at the stack, and if I knew I'd used word or dword instead Smile
Anyways, I fixed it by using a dword value instead and by using the stdcall macro.

Thanks again.
Post 19 Jan 2005, 14:37
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.