0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

「手探りでCUI OS作成に挑む」関数説明篇 print_string(文字列表示)

Posted at

「手探りでCUI OS作成に挑む」連載

この記事は「手探りでCUI OS作成に挑む」連載の一部です。
全体の目次は「手探りでCUI OS作成に挑む」連載目次を御覧下さい。

目的

db命令で設定された文字列を画面上に表示する。

検証コード

boot.asm
[org 0x7C00]
[bits 16]

start:
    ;レジスタの初期化
    xor ax, ax
    mov ds, ax
    mov es, ax

    
    mov si, msg1      ;siをmsg1に登録された文字列の一文字目`h`の番地を入れる
    call print_string
    
    mov si, msg2
    call print_string

    ;CPU停止
    cli
    hlt

print_string:
    pusha
    mov ah, 0x0E     ;1文字出力
    mov bh, 0
.print_loop:
    lodsb            ;SIの示すアドレスから1バイトをALに読み込み、SIを+1(次の文字へ)
    test al, al      ;alが0かどうかを確認する
    jz .done         ;文字が 0 か(=終端記号か)を確認。※'hello',0 文字列の最後に目印の0を入れている
    int 0x10         ;BIOS割り込みで AL の文字を表示
    jmp .print_loop
.done:
    popa
    ret

msg1 db 'hello',0
msg2 db 'world',0

times 510-($-$$) db 0
dw 0xAA55

動作確認

nasm -f bin boot.asm -o boot.bin
qemu-system-i386 -fda boot.bin

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?