嘿我试图加载一个我放在引导加载程序末尾的字符串,或者是0x7e00。我尝试使用int 13h将字符串加载到内存中,然后将其打印到屏幕上。我检查错误,但没有发生错误。但是,没有任何东西被打印到屏幕上,只是挂着一个黑屏。
这是我的引导加载程序代码:
[org 0x7c00]
[bits 16]
mov byte [driveno], dl ;save dl
;set up stack
xor ax, ax
cli
mov ss, ax
mov sp, 0x9000
sti
;set up segment regs
jmp 0x0000:start
start:
xor ax, ax
mov ds, ax
mov es, ax
;reset drive
xor ax, ax
int 0x13
;read 2nd sector
mov al, 0x01
mov bx, 0
mov es, bx
mov bx, 0x7e00
mov cx, 0x0002
xor dh, dh
mov dl, byte [driveno]
mov ah, 0x02
int 0x13
jc read_error ;Apparently no error!!!
mov ah, 0x01 ;Check status of last operation
int 0x13
mov dx, ax ;Print the value stored in ax
call printhex ;This outputs 0x0001 or al=01 so I get an invalid function error?
mov si, 0x7e00 ;print my "loaded" message
call print
mov si, teststr ;test if my print function works, it does.
call print
cli
hlt
jmp $
read_error:
mov si, error
call print
ret
print:
loop:
lodsb
or al, al
jz done
mov ah, 0x0e
mov bx, 0x0003 ;page 0 and default color
int 0x10
jmp loop
done:
ret
printhex: ;This method allows me to see what is inside of registers such as ax.
push bx
push si
mov si, hex_template
mov bx, dx
shr bx, 12
mov bx, [bx+hexabet]
mov [hex_template+2], bl
mov bx, dx
shr bx, 8
and bx, 0x000f
mov bx, [bx+hexabet]
mov [hex_template+3], bl
mov bx, dx
shr bx, 4
and bx, 0x000f
mov bx, [bx+hexabet]
mov [hex_template+4], bl
mov bx, dx
and bx, 0x000f
mov bx, [bx+hexabet]
mov [hex_template+5], bl
call print
pop si
pop bx
ret
error db 'Error',0
teststr db 'Printing works',0
hex_template db '0x????',0 ;For my hex print method
hexabet db '0123456789abcdef' ;Also for my hex print method
driveno db 0 ;Storing dl
times 510-($-$$) db 0
dw 0xaa55
db 'ABCD',0 ;this needs to be loaded
times 1024-($-$$) db 0 ;fill my file so it is 2 whole sectors
我用
编译nasm -f bin boot.asm -o boot.bin
我使用
写信给我的usbdd if=boot.bin of=\\.\e: bs=512 count=2
有谁知道为什么我的消息在我启动到usb时没有显示? 谢谢!
答案 0 :(得分:0)
您应该像这样重新安排代码。
[org 0x7c00]
[bits 16]
jmp 0x00:0x7c00
start:
;set up stack and segment registers
xor ax, ax
cli
mov ds,ax
mov es,ax
mov ss, ax
mov sp, 0x9000
sti
;Save driveno
mov byte[driveno],dl
;reset drive
xor ax, ax
int 0x13
;read 2nd sector
mov al, 0x01
mov bx, 0
mov es, bx
mov bx, 0x7e00
mov cx, 0x0002
xor dh, dh
mov dl, byte [driveno]
mov ah, 0x02
int 0x13
jc read_error ;Apparently no error!!!
mov ah, 0x01 ;Check status of last operation
int 0x13
mov dx, ax ;Print the value stored in ax
call printhex ;This outputs 0x0001 or al=01 so I get an invalid function error?
mov si, 0x7e00 ;print my "loaded" message
call print
mov si, teststr ;test if my print function works, it does.
call print
cli
hlt
jmp $
read_error:
mov si, error
call print
ret
print:
loop:
lodsb
or al, al
jz done
mov ah, 0x0e
mov bx, 0x0003 ;page 0 and default color
int 0x10
jmp loop
done:
ret
printhex: ;This method allows me to see what is inside of registers such as ax.
push bx
push si
mov si, hex_template
mov bx, dx
shr bx, 12
mov bx, [bx+hexabet]
mov [hex_template+2], bl
mov bx, dx
shr bx, 8
and bx, 0x000f
mov bx, [bx+hexabet]
mov [hex_template+3], bl
mov bx, dx
shr bx, 4
and bx, 0x000f
mov bx, [bx+hexabet]
mov [hex_template+4], bl
mov bx, dx
and bx, 0x000f
mov bx, [bx+hexabet]
mov [hex_template+5], bl
call print
pop si
pop bx
ret
error db 'Error',0
teststr db 'Printing works',0
hex_template db '0x????',0 ;For my hex print method
hexabet db '0123456789abcdef' ;Also for my hex print method
driveno db 0 ;Storing dl
times 510-($-$$) db 0
dw 0xaa55
db 'ABCD',0 ;this needs to be loaded
times 1024-($-$$) db 0 ;fill my file so it is 2 whole sectors
应该已经解决了你的问题。