汇编语言2推和流行书 [英] Assembly Language 2 Book on Push and Pop

查看:137
本文介绍了汇编语言2推和流行书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一个问题 关于示例代码运行时将发生什么的陈述是正确的?

1: main PROC
2: mov eax,30
3: push eax
4: push 40
5: call Ex3Sub
6: INVOKE ExitProcess,0
7: main ENDP
8:
9: Ex3Sub PROC
10: pusha
11: mov eax,80
12: popa
13: ret
14: Ex3Sub ENDP

a. EAX在第6行等于40

b.该程序将在第6行出现运行时错误而终止

c. EAX在第6行等于30

d.程序将在第13行出现运行时错误而终止

第二个问题 关于示例代码运行时将发生什么的陈述是正确的?

1: main PROC
2: push 10
3: push 20
4: call Ex2Sub
5: pop eax
6: INVOKE ExitProcess,0
7: main ENDP
8:
9: Ex2Sub PROC
10: pop eax
11: ret
12: Ex2Sub ENDP

a. EAX在第6行等于10

b.该程序将在第10行上因运行时错误而终止

c. EAX在第6行等于20

d.该程序将在第11行上因运行时错误而停止运行

1.通过观察这一点,我认为EAX在第6行的末尾仍将等于30,因为eax只是被压入堆栈而不是值的改变

2.由于LIFO(后进先出),我认为这等于10. EAX等于10,因为它是最后一个.

这是一个新概念,我们将不胜感激.

解决方案

您获得了第一个权利.第二个比较棘手,它很可能在第11行崩溃(答案为d).这是因为在Ex2Sub中,pop eax从堆栈中删除最上面的项,这是返回地址.因此,当ret尝试执行相同操作时,它将看到下一个项目,该项目为20,不太可能是正确的代码地址.

First question Which statement is true about what will happen when the example code runs?

1: main PROC
2: mov eax,30
3: push eax
4: push 40
5: call Ex3Sub
6: INVOKE ExitProcess,0
7: main ENDP
8:
9: Ex3Sub PROC
10: pusha
11: mov eax,80
12: popa
13: ret
14: Ex3Sub ENDP

a. EAX will equal 40 on line 6

b. The program will halt with a runtime error on Line 6

c. EAX will equal 30 on line 6

d. The program will halt with a runtime error on Line 13

Second Question Which statement is true about what will happen when the example code runs?

1: main PROC
2: push 10
3: push 20
4: call Ex2Sub
5: pop eax
6: INVOKE ExitProcess,0
7: main ENDP
8:
9: Ex2Sub PROC
10: pop eax
11: ret
12: Ex2Sub ENDP

a. EAX will equal 10 on line 6

b. The program will halt with a runtime error on Line 10

c. EAX will equal 20 on line 6

d. The program will halt with a runtime error on Line 11

1. By looking at this I think that EAX would still equal 30 at the end of line 6 because eax was just pushed on the stack not a change in value

2. This one I would believe it would equal 10 because of LIFO (last in first out). EAX would equal 10 because it was the last one in.

This is a new concept, any help would be appreciated.

解决方案

You got the first one right. The second one is tricky, it will most probably crash on line 11 (answer d). That's because in Ex2Sub the pop eax removes the topmost item from the stack, which is the return address. So when ret tries to do the same, it will see the next item, which was 20 and unlikely to be a correct code address.

这篇关于汇编语言2推和流行书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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