我正在学习实模式编程,并在这里找到了一篇关于 SO 的帖子,这对我来说非常有用但我对给定代码中的工作方式有些疑问
;This is NASM
BITS 16 ; 16 bits!
start: ; Entry point
mov ax, 07C0h ; Move the starting address (after this bootloader) into 'ax'
add ax, 288 ; Leave 288 bytes before the stack beginning for some reason
mov ss, ax ; Show 'stack segment' where our stack starts
mov sp, 4096 ; Tell 'stack pointer' that our stack is 4K in size
mov ax, 07C0h ; Use 'ax' as temporary variable for setting 'ds'
mov ds, ax ; Set data segment to where we're loaded
mov si, text_string ; Put string position into SI (the reg used for this!)
call print_string ; Call our string-printing routine
jmp $ ; Jump here - infinite loop!
text_string db 'This is my cool new OS!', 0 ; Our null terminated string
; For some reason declared after use
print_string: ; Routine: output string in SI to screen
mov ah, 0Eh ; I don't know what this does..
; Continue on to 'repeat'
.repeat:
lodsb ; Get character from DS:SI into AL
cmp al, 0 ; If end of text_string
je .done ; We're done here
int 10h ; Otherwise, print the character (What 10h means)
jmp .repeat ; And repeat
.done:
ret
times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
dw 0xAA55 ; The standard PC 'magic word' boot signature
1)DS和CS在这里重叠吗?
2)CS是否从0h位置开始?,所附图像显示了 512 个字节,它们是由汇编器生成的引导扇区
3)DS和CS都是从07c00H开始的吗??首先,代码部分是在放入文本字符串的数据之前填写的
4)堆栈从07c00+288开始??并且 mov sp,4096 将定义大小为 (07c00+288+4096-07c00+288) 的堆栈。