The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: *DEAD* on December 17, 2007, 06:38:17 AM

Title: question about push IMMEDIATE
Post by: *DEAD* on December 17, 2007, 06:38:17 AM
Hi, hope i got the terminology right above
anyway, ive just written a small snippet of code for doing a prime test on a number. Now i want this to be called (i dont know if im still allowed to call it a function in asm, lol) and i want to push either a 0 or 1 on the stack depending on the result of the test. Now, i just though about this, but if i simply go
push 1
then what goes on the stack. Is it a BYTE, WORD, DWORD ect. This would of course be useful to know when popping the value again in the calling function.
Title: Re: question about push IMMEDIATE
Post by: MichaelW on December 17, 2007, 07:35:06 AM
In 32-bit code a DWORD would be pushed.

print uhex$(esp),13,10
push 1
print uhex$(esp),13,10
pop eax
print uhex$(eax),13,10


0012FFC0
0012FFBC
00000001

Title: Re: question about push IMMEDIATE
Post by: *DEAD* on December 17, 2007, 08:21:13 AM
ok thx
Title: Re: question about push IMMEDIATE
Post by: sinsi on December 17, 2007, 09:07:27 AM
And, of course, in 16-bit code a WORD is always pushed - you can't PUSH a BYTE

.data
  a_byte db 1
.code
  push a_byte

error A2070: invalid instruction operands

But with INVOKE, you can (indirectly)

my_proc proto c x:byte
.data
  a_byte db 1
.code
  invoke my_proc,a_byte
;the invoke gets translated as
;  mov al,a_byte
;  push ax
;  call my_proc