我需要帮助来处理这个push pop的情况。我试图写一个HLA汇编语言程序,实现一个函数,正确识别当所有四个参数是相同的,并返回一个布尔值在AL(1当所有四个值相等;
0)。下面是我的代码:program same;
#include("stdlib.hhf");
static
w : int16 :=0;
x : int16 :=0;
y : int16 :=0;
z : int16 :=0;
temp : int16;
// Function theSame //
procedure theSame(w:int16; x:int16; y:int16; z:int16); @nodisplay; @noframe;
static
returnAddress : dword;
similar: int16;
begin theSame;
pop(returnAddress);
pop(similar); // Padding - stacking must be 32 bit align
pop(z);
pop(y);
pop(x);
pop(w);
push(returnAddress);
stdout.put( "w = ", w, nl );
stdout.put( "x = ", x, nl );
stdout.put( "y = ", y, nl );
stdout.put( "z = ", z, nl );
stdout.put( "cmp w x ", nl );
mov(w,AX);
cmp(AX,x);
je Equal;
jne Notequal; // (w==x)
stdout.put( "cmp x y ", nl );
mov(x,AX);
cmp(AX,y);
je Equal;
jne Notequal; // (x==y)
stdout.put( "cmp y z ", nl );
mov(y,AX);
cmp(AX,z);
je Equal;
jne Notequal; // (y==z)
stdout.put( "cmp z w ", nl );
mov(z,AX);
cmp(AX,w);
je Equal;
jne Notequal; // (w==z)
Equal:
stdout.put( "equal", nl );
mov(1,AX);
push(similar); // padding
jmp ExitSequence;
Notequal:
stdout.put( "not equal", nl );
mov(0,AX);
push(similar); // padding
jmp ExitSequence;
ExitSequence:
ret();
end theSame;
begin same;
stdout.put("Feed Me W: ");
stdin.get(w);
push(w);
stdout.put("Feed Me X: ");
stdin.get(x);
push(x);
stdout.put("Feed Me Y: ");
stdin.get(y);
push(y);
stdout.put("Feed Me Z: ");
stdin.get(z);
push(z);
call theSame;
cmp(AX, 1);
je YESEQUAL;
jmp NOEQUAL;
YESEQUAL:
stdout.put("True", nl);
jmp EndProgram;
NOEQUAL:
stdout.put("False", nl);
jmp EndProgram;
stdout.newln();
EndProgram:
end same;
但是,输出是这样的:
输入:
喂我W: 8喂我X: 7喂我
输出:
<>以前W: -165X: 8Y: 7Z: 6CMP w xnot equal为什么它们的值是相同的?搞不懂push and pop是怎么工作的。谢谢你。
pop(similar); // Padding - stacking must be 32 bit align
显然你需要删除这个pop(similar)
指令。如果你离开它,它获得z参数的值。并使w从堆栈中获取垃圾!不要忘记删除push(similar)
指令。
进入时的堆栈布局:
x x 5 6 7 8 -165
----
^ ^ ^ ^ ^
| z y x w all 4 words
dword return address
pop(returnAddress);
pop(z);
pop(y);
pop(x);
pop(w);
push(returnAddress);