我在實模式下學習編程重疊,發現這裏的SO後這對我來說 相當有用的,但我有一個關於事情是如何在給定的代碼工作的一些疑慮是DS和CS在此代碼
;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)的堆棧。
但操作碼(這是代碼的一部分)從地址0開始,爲什麼288是由16這裏 –
@AmitSinghTomar乘我不知道你的十六進制轉儲是什麼。但是它會在實際加載到內存之前經歷重定位過程。在CPU的文字地址爲'0'處有中斷向量等,所以代碼不可能從'0'開始。 – lurker