The stack in assembler (notes)

来源:互联网 发布:哈尔滨淘宝代运营 编辑:程序博客网 时间:2024/04/30 07:11

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    100hMOV    AX, 1212h   ; store 1212h in AX.MOV    BX, 3434h   ; store 3434h in BXPUSH   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.RETEND

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.

原创粉丝点击