Stack Initialization Problem in Real Mode: 如何正确初始化堆栈?

huangapple go评论64阅读模式
英文:

Stack Initialization Problem in Real Mode: How to Properly Initialize the stack?

问题

我正在用x86汇编语言编写一个简单的引导加载程序,以下是代码部分:

org 0x7C00
section boot start=0x7C00

; 初始化栈
mov ax, 0xF000
mov ss, ax

mov sp, 0xFFFF
mov bp, 0xFFFF

; 加载额外的扇区
mov ah, 0x02
mov al, 0x02    ; 扇区数
mov ch, 0x00    ; 柱面
mov cl, 0x02    ; 第2扇区
mov dh, 0x00    ; 磁头

; 地址 = es*0x10 + bx
xor bx, bx  ; 将0移到es
mov ds, bx
mov es, bx
mov bx, 0x8000

int 0x13

jmp 0x8000

times 510-($-$$) db 0

db 0x55, 0xAA     ; 结束引导扇区

当我删除栈初始化代码时,引导加载程序可以正常工作,并且BIOS中断被执行,但当我添加该代码后,什么都不会发生,中断不起作用。

我做错了什么?为什么会发生这种情况?

英文:

I am writing a simple boot loader in x86 assembly, here is the code for it :

org 0x7C00
section boot start=0x7C00


; initializing the stack 
mov ax,0xF000
mov ss,ax 

mov sp,0xFFFF
mov bp,0xFFFF




; loading the additional sectors 
mov ah,0x02
mov al,0x02    ; number of sectors
mov ch,0x00    ; cylinder 
mov cl,0x02    ; sector 2
mov dh,0x00    ; head 

; address = es*0x10 + bx
xor bx,bx  ; moving 0 to es 
mov ds,bx
mov es,bx    
mov bx,0x8000

int 0x13

jmp 0x8000

times 510-($-$$) db 0 

db 0x55, 0xaa     ; Ending the boot sector

the problem is that whenever I remove the stack initialization code the boot loader works just fine and the BIOS interrupts are executed, but when I add the code back in nothing happens and the interrupts don't work.

what am I doing wrong ?? and why is this happening ??

答案1

得分: 2

A common setting for a MBR boot ss:sp is to set them to 00000h:07c00h, so that the stack ends just before the start of the boot code.

英文:

A common setting for a MBR boot ss:sp is to set them to 00000h:07c00h, so that the stack ends just before the start of the boot code.

huangapple
  • 本文由 发表于 2023年6月22日 20:21:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76531840.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定