为什么我不能访问堆栈的中间?

时间:2018-09-21 17:37:19

标签: assembly x86 bootloader

我正在研究this tutorial-我所在的部分使引导程序访问堆栈。我正在尝试理解以下代码:

mov ah, 0x0e     ; int 0x10 writes to tty
mov bp, 0x8000   ; set the base of our stack
mov sp, bp       ; there's nothing in the stack, so the base pointer
                 ; and the stack pointer are the same. 

push 'A'        
push 'B'
push 'C'         ; bp at 0x8000, sp at 0x7ffe. 

mov al, [0x7ffe]
int 0x10         ; this prints what's at the top of the stack, 'A'

mov al, [0x7fff]
int 0x10         ; this prints garbage or nothing, for some reason, but
                 ; I would expect it to print 'B'

```

我知道我希望通过pushpop与堆栈进行交互。但是,如果我可以直接访问堆栈的顶部,为什么不能访问中间或底部?在启动过程的早期,CPU或MMU是否正在实施访问限制?

如果有帮助,我正在通过以下方式测试此代码:

nasm -f bin 'this_code.asm' -o boot.bin
qemu-system-x86_64 --nographic boot.bin

0 个答案:

没有答案
相关问题