Reputation: 39
My current code works, and is as follows:
movzx ecx, var1
lea eax, var2
push eax
push ecx
call func1
//...
and func1 is:
push ebp
mov ebp, esp
mov ecx, [ebp + 8]
mov eax, [ebp + 12]
push edi
push ecx
not byte ptr[eax]
//...
However, I wish to push the address of var2 directly, along with simply pushing the value of var1 like so, but I'm having trouble figuring out how:
push var1
push var2 //address of)
call func1
Any and all help would be greatly appreciated.
Upvotes: 0
Views: 102
Reputation: 10391
With compiler EMU8086 you can do it. Next is your code with some changes (I'm using 16 bit registers, that's why BP+4 and BP+6) :
.stack 100h
.data
var1 dw 25 ;VAR1 = 25.
var2 dw 800 ;VAR2 = 800.
.code
mov ax, @data
mov ds, ax
push var1 ;PUSH 25.
push offset var2 ;PUSH ADDRESS OF 800.
call func1
mov ax, 4c00h
int 21h ;FINISH.
func1 proc
push bp
mov bp, sp
mov si, [ bp + 4 ] ;POP ADDRESS OF 800.
mov ax, [ bp + 6 ] ;POP 25.
not [ byte ptr si ] ;CX CANNOT BE USED AS POINTER.
pop bp
ret
func1 endp
The address of 800 is extracted into SI instead of CX because CX cannot be used to point to the address.
Remember that things in stack are stored upside down : 25 is pushed first then the address of 800, that's why the address is in position BP+4 and 25 in BP+6.
Upvotes: 0
Reputation: 3227
There is no way to get the address of a register value.
However, there are two things you can do:
If the value is in the psuedo-register var2
and is created through the operation of your program (i.e, isn't a syscall return register, etc.), you could simply do the following instead of mov var2, [avar2]
mov var2, avar2
If that doesn't suit you, you can push var2
to the stack and get the address from esp
, e.g
push var2
lea avar2, [esp-4]
Upvotes: 1
Reputation: 29052
Well, if the byte variable var1
has a DWORD space(4-bytes) in memory and is zero extended, you could just PUSH
it. The LEA
of var2'
could be replaced if the address of var2
is at a constant address in the .data
segment. Like this:
push var1
push offset var2
call func1
Under these conditions your requirements would be easily satisfiable.
Upvotes: 2