RTC から時刻を取得して表示
まぁ Hello World! だけではつまらないなと思って。
ひたすら ah=0x02, int 0x1A で RTC を読み出して表示する。
各値は BCD という表現で格納されている。今まで聞いたことすらなかった。
http://ja.wikipedia.org/wiki/BCD
ふむ、こういう場合にはむしろ扱いやすい形かもしれない。
下のコードではマクロ中で適当に and をとって十の位と一の位に分割してそれぞれに 0x30 を加えてASCIIコードにしている。
org 0x7C00 ; start address for BIOS %macro print_bcd 2 ; prepare for int 0x10 mov ah, 0x0E mov bh, 0 mov bl, 0x07 ; print BCD %1, using %2 as temporary mov %2x, 0xF00F and %2h, %1 shr %2h, 4 and %2l, %1 add %2x, 0x3030 mov al, %2h int 0x10 mov al, %2l int 0x10 %endmacro start: ; get current cursor position mov ah, 0x03 mov bh, 0 int 0x10 push dx ; save cursor position print_rtc: ; set cursor position pop dx ; restore cursor position mov ah, 0x02 mov bh, 0 int 0x10 push dx ; get RTC mov ah, 0x02 int 0x1A push dx ; save dx(contains sec) ; print hour print_bcd ch, d mov al, ':' int 0x10 ; print min print_bcd cl, d mov al, ':' int 0x10 pop dx ; restore dx(contains sec) ; print sec print_bcd dh, c jmp print_rtc ; infinite loop padding: times 510-($-$$) db 0 dw 0xAA55