2014-04-17 73 views
0

我在做一個系統編程任務,但是面臨一個小問題。程序集從一個扇區加載程序並返回

我已經設法寫入我的引導扇區,並能夠調用另一個扇區,我用int 13讀過。所有指令都執行並且代碼返回到引導扇區。

,但我無法訪問我在第二扇區聲明的變量在第二個部門

這裏使用的是代碼

[bits 16] 
[org 0x7c00] 

mov ah,2 
mov al,1 ;Number of sectors to read 
mov ch,0 ;Cylinder number (10 bit value; upper 2 bits in CL) 
mov cl,2 ;Starting sector number 
mov dh,0 ;Head number 
mov dl,0 ;Drive number 

mov bx,cs 
mov es,bx 
mov bx,here 

int 13h 

jc error 

call here 


error: 
mov ah,0eh 
mov al,'E' 
mov bl,7 
mov bh,0 
int 10h 
jmp $ 

exit: 
mov ah,0eh 
mov al,'F' 
mov bl,7 
mov bh,0 
int 10h 
jmp $ 

here: 


jmp $ 




times 510 - ($-$$) db 0 
dw 0xaa55 

Sector2.asm

[bits 16] 

mov bx,cs 
mov ds,bx 

jmp start 

msg db "Welcome to my OSD",0 

start: 

mov si,0 
mov si,msg 

mov ah,0eh 
mov al,':' 
int 10h 

mov ah,0eh 
mov al,[si] ;; HERE IS THE PROBLEM IT PRINTS GARBAGE 
int 10h 
inc si 
mov ah,0eh 
mov al,[si] ;; HERE IS THE PROBLEM IT PRINTS GARBAGE 
int 10h 
inc si 
mov ah,0eh 
mov al,[si] ;; HERE IS THE PROBLEM IT PRINTS GARBAGE 
int 10h 


ret 





times 510-($-$$) db 0 
dw 0x0055 

回答

0

在爲了讓Nasm計算出msg的正確地址,需要告知org對應於實際加載代碼的位置。您似乎將其加載到「相同的段」(大概爲0)並抵消了herehere將隨您的代碼更改而變化。如果您將here:標籤放在最後 - 在引導信號之後?然後它將在一個已知的偏移-0x7E00 - 你可以org你的第二個文件。我認爲這會奏效。如果你確實需要在「工作代碼」之後加載你的第二個扇區,那麼你必須計算你的第二個文件的偏移量和org