Assembly Language 2 Book on Push and Pop

匿名 (未验证) 提交于 2019-12-03 08:50:26

问题:

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.

回答1:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!