目的
以下のIBMBIOSで実装されているALに入っている0〜15の値を、'0'〜'F'に変換して画面表示する関数を追いました。
;--------------------------------------------
; CONVERT AND PRINT ASCII CODE
;
; AL MUST CONTAIN NUMBER TO BE CONVERTED.
; AX AND BX DESTROYED.
;--------------------------------------------
XLAT_PRINT_CODE PROC NEAR
PUSH DS ;SAVE DS VALUE
PUSH CS ;POINT DS TO CODE SEG
POP DS
MOV BX,0E4B7H ; OFFSET ASCII_TBL-XLAT TABLE
XLATB
MOV AH,14
MOV BH,0
INT 10H ;CALL VIDEO_IO
POP DS ;RESTORE ORIG VALUE IN DS
RET
XLAT_PRINT_CODE ENDP
; ...省略...
ASCII_TBL DB '0123456789ABCDEF'
NASM用に修正したコード
boot.asm
[org 0x7C00]
bits 16
start:
mov al,0x00
call xlat_print_code
mov al,0x01
call xlat_print_code
mov al,0x02
call xlat_print_code
mov al,0x03
call xlat_print_code
mov al,0x04
call xlat_print_code
mov al,0x05
call xlat_print_code
mov al,0x06
call xlat_print_code
mov al,0x07
call xlat_print_code
mov al,0x08
call xlat_print_code
mov al,0x09
call xlat_print_code
mov al,0x0A
call xlat_print_code
mov al,0x0B
call xlat_print_code
mov al,0x0C
call xlat_print_code
mov al,0x0D
call xlat_print_code
mov al,0x0E
call xlat_print_code
mov al,0x0F
call xlat_print_code
hlt_loop:
cli
hlt
loop hlt_loop
xlat_print_code:
push ds ; ds退避
push cs ; ds=cs
pop ds
mov bx, ascii_tbl
xlatb ; al = [ds:bx + al]
mov ah, 14 ; 14=0x0e AH=0x0eは1文字出力
mov bh, 0
int 10h
pop ds
ret
ascii_tbl db '0123456789ABCDEF'
times 510-($-$$) db 0
dw 0xAA55
検証
nasm -f bin boot.asm -o boot.bin
qemu-system-i386 -fda boot.bin
lsblk
sudo dd if=boot.bin of=/dev/sdb bs=512 count=2 conv=notrunc