空终止改变字符串
Null-terminating changes the string
我有这段代码应该打印字符串的第一个字母:
mov bx, message ; Move the address of the message to bx
add bx, 0x7c00 ; Adding the padding of bootsector to bx
mov al, [bx] ; Move the value at the address in bx to al
int 0x10 ; Interrupt drawing the character in al to screen
为什么这不起作用:
message:
db "Test", 0
但这行得通:
message:
db "Test", 0, 0
第一个打印一些 运行dom 字符,第二个总是我消息的第一个字母。
代码用 NASM 编译成 .bin 和 运行 作为 Bochs 中的引导扇区。
**编辑
完整代码:
mov ah, 0x0e
message:
db 'Booting MainOPS', 0
printTheMessage:
mov bx, message
add bx, 0x7c00
mov al, [bx]
int 0x10
jmp $
times 510 - ($-$$) db 0
dw 0xaa55
和@Jester 猜的一样。你执行 message
作为代码。代码执行从 mov ah, 0x0e
开始,然后继续执行紧随其后的字节,即字符串 'Booting MainOPS', 0
,然后是 printTheMessage
代码。
要么将message
移动到无限循环之后,要么在第一个指令之后将jmp
添加到printTheMessage
。
我有这段代码应该打印字符串的第一个字母:
mov bx, message ; Move the address of the message to bx
add bx, 0x7c00 ; Adding the padding of bootsector to bx
mov al, [bx] ; Move the value at the address in bx to al
int 0x10 ; Interrupt drawing the character in al to screen
为什么这不起作用:
message:
db "Test", 0
但这行得通:
message:
db "Test", 0, 0
第一个打印一些 运行dom 字符,第二个总是我消息的第一个字母。
代码用 NASM 编译成 .bin 和 运行 作为 Bochs 中的引导扇区。
**编辑
完整代码:
mov ah, 0x0e
message:
db 'Booting MainOPS', 0
printTheMessage:
mov bx, message
add bx, 0x7c00
mov al, [bx]
int 0x10
jmp $
times 510 - ($-$$) db 0
dw 0xaa55
和@Jester 猜的一样。你执行 message
作为代码。代码执行从 mov ah, 0x0e
开始,然后继续执行紧随其后的字节,即字符串 'Booting MainOPS', 0
,然后是 printTheMessage
代码。
要么将message
移动到无限循环之后,要么在第一个指令之后将jmp
添加到printTheMessage
。