程序集从扇区加载程序并返回

时间:2014-04-17 05:47:51

标签: assembly x86 dos

我正在进行系统编程分配但面临轻微问题。

我已经设法编写我的引导扇区并能够调用另一个使用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

1 个答案:

答案 0 :(得分:0)

为了让Nasm计算msg的正确地址,需要告诉org对应代码实际加载的位置。您似乎将其加载到“相同段”(可能为0)并偏移here。随着代码的变化,here会发生变化。如果你把here:标签放在最后 - 启动sig之后怎么样?然后它将在一个已知的偏移量-0x7E00 - 你可以org你的第二个文件。我认为那会有用。如果您确实需要在“工作代码”之后加载第二个扇区,则必须计算该偏移量并将org第二个文件计算到该值。

相关问题