2015-05-27 15 views
0
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 

我試圖用每行3個字符串替換字符串'測試1'。 輸出應該類似於:我需要幫助將一個字符串添加到.asm文件中的一個新行

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換行的開始/ New Line)轉到下一行

在所有字符串的末尾。

+0

是的,但我也會將'0x0D'添加到'0x0A',以便在行的開頭返回光標。 – user35443

相關問題