The stack in assembler (notes)

http://www.emu8086.com/assembler_tutorial/asm_tutorial_09.html

1.

keep temporary data;

used by CALL;

RET--compared with IRET used in INT.

 

2. 

PUSH-stores 16 bit value (REG/SREG/memory/immediate)(immediate for 80186 and later)

POP-gets 16 bit value (REG/SRET/memory)(Note: SREG except CS)

 

they're useful due to

a. limited number of registers.

b. for exchange the values

example:

ORG    100h
MOV    AX, 1212h   ; store 1212h in AX.
MOV    BX, 3434h   ; store 3434h in BX

PUSH   AX          ; store value of AX in stack.
PUSH   BX          ; store value of BX in stack.

POP    AX          ; set AX to original value of BX.
POP    BX          ; set BX to original value of AX.

RET
END

3.LIFO

impt to do equal number of PUSHs and POPs

otherwise the stack maybe corrupted and it will be impossible to return to os

when program starts there is a return address in stack.(genrally 0000h)

 

4. memory area: SS and SP.

PUSH sourse: (SP-2)-->(SP), write source to SS:SP

POP destination: write the value at SS:SP to destination, (SP+2)-->(SP)

 

5. The top of the stack: the current address pointed by SS:SP

 

6. For COM files, stack seg is generally the code seg and SP=0FFFEh

AT SS:0FFFEh stored a return address of RET that is executed in the end of the program.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值