查看 7C00h 值,您可能正在使用引导加载程序。
并且您希望堆栈位于引导加载程序下方。
您必须做出的一个重要选择是您希望如何继续使用在启动时有效的分段寻址方案。
ORG 7C00h
这表示代码的第一个字节将位于偏移量 7C00h。为此,您必须将段寄存器初始化为 0000h。请记住,引导加载程序是由 BIOS 在线性地址 00007C00h 处加载的,这相当于段:偏移量对 0000h:7C00h。
如果您要更改SP 寄存器,那么还要更改SS 段寄存器。您不知道它在代码开头包含什么,您应该(大多数)始终同时修改这些寄存器。首先分配SS,然后直接分配SP。 mov 或 pop 到 SS 会阻止此指令和以下指令之间的多种中断,以便您可以安全地设置一致的(2 寄存器)堆栈指针。
mov ss, ax
mov bp, ax <== This ignored the above safeguard!
mov sp, bp
ORG 7C00h
mov bp, 7C00h
xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax ; \ Keep these close together
mov sp, bp ; /
push 'A' ; This writes 0000h:7BFEh
mov bx, 0007h ; DisplayPage and GraphicsColor
mov al, [7BFEh] ; This requires DS=0
mov ah, 0Eh ; BIOS.Teletype
int 10h
作为替代方案,由于您已设置 BP=7C00h,您可以通过
mov al, [bp-2] 读取堆叠字符。
ORG 0000h
这表示代码的第一个字节将位于偏移量 0000h。为了使其正常工作,您必须将一些段寄存器初始化为 07C0h。请记住,引导加载程序是由 BIOS 在线性地址 00007C00h 处加载的,这相当于段:偏移量对 07C0h:0000h。
因为堆栈必须低于引导加载程序,SS 段寄存器将与其他段寄存器不同!
ORG 0000h
mov bp, 7C00h
mov ax, 07C0h
mov ds, ax
mov es, ax
xor ax, ax
mov ss, ax ; \ Keep these close together
mov sp, bp ; /
push 'A' ; This writes 0000h:7BFEh
mov bx, 0007h ; DisplayPage and GraphicsColor
mov al, [bp-2] ; This uses SS by default
mov ah, 0Eh ; BIOS.Teletype
int 10h
组织 0200h
我包含这个是为了表明线性地址对段:偏移量有很多转换。
ORG 0200h 表示代码的第一个字节将位于偏移量 0200h。为此,您必须将段寄存器初始化为 07A0h。请记住,引导加载程序是由 BIOS 在线性地址 00007C00h 处加载的,这相当于段:偏移量对 07A0h:0200h。
由于 512 字节堆栈位于引导加载程序下方,SS 段寄存器将再次等于其他段寄存器!
ORG 0200h
mov bp, 0200h
mov ax, 07A0h
mov ds, ax
mov es, ax
mov ss, ax ; \ Keep these close together
mov sp, bp ; /
push 'A' ; This writes 07A0h:01FEh
mov bx, 0007h ; DisplayPage and GraphicsColor
mov al, [bp-2] ; This uses SS by default
mov ah, 0Eh ; BIOS.Teletype
int 10h
您也可以使用mov al, [01FEh] 获取字符。