操作系统开发 – 婴儿教程 8

来源:互联网 发布:森口博子 知乎 编辑:程序博客网 时间:2024/04/28 04:23

32-bit printing

Here is the same non-BIOS screen print AsmExample as before, but adjusted to use 32-bit registers and offsets. The 'complex' string instructions have been replaced.

;----------------------dochar:    call cprint              ; print one charactersprint:    mov eax, [esi]          ; string char to AL    lea esi, [esi+1]    cmp al, 0    jne dochar               ; else, we're done    add byte [ypos], 1       ; down one row    mov byte [xpos], 0       ; back to left    ret cprint:    mov ah, 0x0F             ; attrib = white on black    mov ecx, eax             ; save char/attribute    movzx eax, byte [ypos]    mov edx, 160             ; 2 bytes (char/attrib)    mul edx                  ; for 80 columns    movzx ebx, byte [xpos]    shl ebx, 1               ; times 2 to skip attrib     mov edi, 0xb8000         ; start of video memory    add edi, eax             ; add y offset    add edi, ebx             ; add x offset     mov eax, ecx             ; restore char/attribute    mov word [ds:edi], ax    add byte [xpos], 1       ; advance to right     ret ;------------------------------------ printreg32:    mov edi, outstr32    mov eax, [reg32]    mov esi, hexstr    mov ecx, 8               ; eight nibbles hexloop:    rol eax, 4               ; leftmost will    mov ebx, eax             ; become rightmost    and ebx, 0x0f ;    mov bl, [esi + ebx]      ; index into hexstr    mov [edi], bl    inc edi    dec ecx    jnz hexloop     mov esi, outstr32    call sprint     ret ;------------------------------------ xpos db 0ypos db 0hexstr db '0123456789ABCDEF'outstr32 db '00000000', 0    ; register valuereg32 dd 0                   ; pass values to printreg32 ;------------------------------------