弹出/推送指令 [英] Pop/Push Instruction

查看:32
本文介绍了弹出/推送指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助解决这种推送流行情况.我正在尝试编写一个 HLA 汇编语言程序,该程序实现了一个函数,该函数可正确识别所有四个参数何时相同并在 AL 中返回一个布尔值(当所有四个值相等时为 1;否则为 0).

这是我目前的代码:

程序相同;#include(stdlib.hhf");静止的w : int16 :=0;x : int16 :=0;y : int16 :=0;z : int16 :=0;温度:int16;//函数相同//过程 theSame(w:int16; x:int16; y:int16; z:int16);@nodisplay;@无框;静止的返回地址:双字;类似:int16;开始相同;弹出(返回地址);流行音乐(类似);//填充 - 堆叠必须是 32 位对齐流行音乐(z);流行音乐(y);流行音乐(x);流行音乐(w);推(返回地址);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 );移动(W,AX);cmp(AX,x);je 平等;jne Notequal;//(w==x)stdout.put(cmp x y", nl);移动(x,AX);cmp(AX,y);je 平等;jne Notequal;//(x==y)stdout.put(cmp y z", nl);移动(Y,AX);cmp(AX,z);je 平等;jne Notequal;//(y==z)stdout.put( "cmp z w ", nl );移动(z,AX);cmp(AX,w);je 平等;jne Notequal;//(w==z)平等的:stdout.put(等于", nl);移动(1,AX);推(类似);//填充jmp 退出序列;注意:stdout.put(不等于",nl);移动(0,AX);推(类似);//填充jmp 退出序列;退出顺序:ret();结束相同;开始相同;stdout.put("Feed Me W:");标准输入.get(w);推(w);stdout.put("Feed Me X:");标准输入.get(x);推(x);stdout.put("Feed Me Y: ");标准输入.get(y);推(y);stdout.put("Feed Me Z:");标准输入.get(z);推(z);调用相同;cmp(AX, 1);je YESEQUAL;jmp NOEQUAL;是:stdout.put("True", nl);jmp 结束程序;不等于:stdout.put("False", nl);jmp 结束程序;标准输出.newln();结束程序:结局一样;

然而,输出结果如下:

输入:

<前>喂我 W: 8喂我 X: 7喂我 Y: 6喂我Z:5

输出:

<前>宽:-165X:8是:7Z:6cmp w x不相等

有什么理由让彼此的价值相同吗?混淆 push 和 pop 的工作原理.谢谢.

解决方案

pop(类似);//填充 - 堆叠必须是 32 位对齐

显然你需要删除这个 pop(similar) 指令.如果你离开它,它会获得 z 参数的值.并让 w 从堆栈中获取垃圾!不要忘记同时删除 push(similar) 指令.

入口时堆栈的布局:

x x 5 6 7 8 -165----^ ^ ^ ^ ^|z y x w 所有 4 个字双字返回地址

pop(returnAddress);流行音乐(z);流行音乐(y);流行音乐(x);流行音乐(w);推(返回地址);

I need help with this push pop situation. I'm trying to write an HLA Assembly language program that implements a function which correctly identifies when all four parameters are the same and returns a boolean value in AL (1 when all four values are equal; 0 otherwise).

Here is my code so far:

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;

However, the output came out to this:

Input:

Feed me W: 8
Feed me X: 7
Feed me Y: 6
Feed me Z: 5

Output:

W: -165
X: 8
Y: 7
Z: 6
cmp w x
not equal

Is there a reason why it's the same value to each other? Confuse on how push and pop works. Thank you.

解决方案

pop(similar); // Padding - stacking must be 32 bit align

Apparently you need to remove this pop(similar) instruction. If you leave it, it obtains the value of the z argument. And makes w get garbage from the stack! Don't forget to also remove the push(similar) instructions.

Layout of your stack on entry:

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);

这篇关于弹出/推送指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆