BITS 16
start:
mov ax, 07C0h
add ax, 288
mov ss, ax
mov sp, 4096
mov ax, 07C0h
mov ds, ax
mov si, boot_message
call print_string
jmp $
boot_message db 'test1', 0
print_string:
mov ah, 0Eh
.repeat:
lodsb
cmp al, 0
je .done
int 10h
jmp .repeat
.done:
ret
times 510-($-$$) db 0
dw 0xAA55
我正在尝试更换字符串'测试1'每行3个字符串。 输出应类似于:
test 1
test 2
test 3
答案 0 :(得分:2)
你实际上已经完成了很大一部分工作。让我们再次查看您的代码
BITS 16
start:
mov ax, 0x8D00 ; 0x7c00 + 0x100 + 0x1000
mov ss, ax
mov sp, 4096 ; this is your stack, not particulary important here...
mov ax, 0x07C0 ; the start of the boot sector in memory
mov ds, ax
mov si, string_1 ; load the string to be printed out
call print_string ; print it
mov si, string_2
call print_string
mov si, string_3
call print_string
jmp $ ; halt the execution here
print_string:
xor bh, bh ; set page number to 0x00
mov bl, 0x0F ; white characters on black background
mov ah, 0x0E ; int 0x10 function: teletype output
.repeat:
lodsb
test al, al
je .done
int 10h
jmp .repeat
.done:
ret
; - STRINGS -
string_1 db 'test 1', 0x0D, 0x0A, 0x00
string_2 db 'test 2', 0x0D, 0x0A, 0x00
string_3 db 'test 3', 0x0D, 0x0A, 0x00
times 510-($-$$) db 0
dw 0xAA55
这里的关键是添加
0x0D
(ASCII回车)将光标返回到行首0x0A
(ASCII换行/新行)转到下一行在所有字符串的末尾。