I have this code and i wanted to ask how to read it to understand what will be the value inside ax after the program reaches line 24 inside the loop what happens when mov ax, [sp+4d] happens does it change the value of ax? to sp+4 i know at the end of the program ax is 15 in hexa just want to know why? thanks so much
Maybe your teacher likes to trick you?
The mov ax, [sp + 4d]
and mov [sp + 4d], ax
instructions are not encodable (*). Their syntax is wrong because the SP
register can not be used as an addressing component. So if you can't even assemble the program, how would you find out the value of the AX
register?
Maybe the teacher expects you to fix the errors and then report about AX
.
In 8086 code, you can address the arguments that are on the stack via the BP
register. Next is a rewrite of the do_something proc that is fine. I additionally preserve the value of BP
.
AX BP RET ARG Stack ARG is the argument pushed at line 17
\----/ \----/ \----/ \----/ RET is the return address
^ ^ ^
| | |
| SP | BP | BP+4
push bp
mov bp, sp
push ax
mov ax, [bp+4]
inc ax
mov [bp+4], ax
pop ax
pop bp
ret
what will be the value inside ax after the program reaches line 24
At line 23, the AX
register will still hold zero since the do_something proc preserved the value of AX
.
At line 24, the AX
register will become 21 because in the amended program , call
ing the do_something proc 21 times will have incremented its stacked argument 21 times, going from 0 to 21.
(*) The mov ax, [esp + 4]
and mov [esp + 4], ax
instructions are fine in code for later cpu's like 80386 because the ESP
register can be used as an addressing component.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.