因为是 ROM 里的数据,所以不可修改。
-a mov ax, 20 mov ds, ax mov ss, ax mov sp, 30 push [0] ; 执行后,寄存器(sp) = 2E push [2] ; 执行后,寄存器(sp) = 2C push [4] ; 执行后,寄存器(sp) = 2A push [6] ; 执行后,寄存器(sp) = 28 pop [6] ; 执行后,寄存器(sp) = 2A pop [4] ; 执行后,寄存器(sp) = 2C pop [2] ; 执行后,寄存器(sp) = 2E pop [0] ; 执行后,寄存器(sp) = 30
逻辑地址: ss:30H 物理地址: ss:30H = $20H \times 16 + 30H = 230H$
前:
后:
不变
没有暂停。 mov sp, 30
立刻执行了。
参考 MASM Reference[1] 和 64-ia-32-architectures-software-developer-vol-3a-part-1-manual[2]。
MASM Reference: Moves the value in the source operand to the destination operand. If the destination operand is SS, interrupts are disabled until the next instruction is executed (except on early versions of the 8088 and 8086).
栈空间00220H ~ 0022fH内存单元值是调用 interrupt-handler 得到的数据。[3]
When the processor performs a call to the exception- or interrupt-handler procedure:
When the stack switch occurs:
a. The segment selector and stack pointer for the stack to be used by the handler are obtained from the TSS
for the currently executing task. On this new stack, the processor pushes the stack segment selector and
stack pointer of the interrupted procedure.
b. The processor then saves the current state of the EFLAGS, CS, and EIP registers on the new stack (see
Figures 6-4).
c. If an exception causes an error code to be saved, it is pushed on the new stack after the EIP value.
源码
assume cs:code code segment start: mov cx, 10 mov dl, '0' s: mov ah, 2 int 21h add dl, 1 loop s mov ah, 4ch int 21h code ends end start
汇编链接过程截图以及运行可执行程序的运行结果截图
assume cs:code code segment mov ax, cs mov ds, ax mov ax, 0020h mov es, ax mov bx, 0 mov cx, 17h s: mov al, [bx] mov es:[bx], al inc bx loop s mov ax, 4c00h int 21h code ends end
mov al, [bx]
从 cs 段开始复制数据,所以 mov ds, ax
上古 8086,参考好难找,Intel 64 手册凑合用。
Page 105, Instructions, MOV Move Data. Microsoft ® MASM Assembly-Language Development System Version 6.1 ↩ ↩︎
6.8.3 Masking Exceptions and Interrupts When Switching Stacks. Intel® 64 and IA-32 Architectures Software Developer’s Manual ↩︎
6.12.1 Exception- or Interrupt-Handler Procedures. Intel® 64 and IA-32 Architectures Software Developer’s Manual ↩︎
Direct Memory Operands. Microsoft ® Programmer’s Guide ↩︎