; global position for vram vb_pos: dd 0 ;;;;;;;;;;;;;;;;;;;;; ;print a 32-bit integer ; input: push u32 ;;;;;;;;;;;;;;;;;;;;;; print_u32: push ebp mov ebp, esp push eax push ebx push ecx ; loop 4 times mov ebx, 8 mov ecx, 32 - 4 .lp: ; eax = thing to print mov eax, dword [ebp + 2 * 4] shr eax, cl and eax, 0xF call al_to_char call print_char sub ecx, 4 dec ebx test ebx, ebx jne .lp pop ecx pop ebx pop eax pop ebp ret ;;;;;;;;;;;;;;;;;;;;; ;print a char in ;;;;;;;;;;;;;;;;;;;;;; print_char: ; input: al = char push edi push eax push esi push ecx ; esi points to current frame buffer mov esi, 0xb8000 ; edi points to offset mov edi, dword [vb_pos] ; handle return character cmp al, 0xA jne .char ; round up to 80 * 2 mov eax, edi add ax, 2 * 80 - 1 mov cl, 2 * 80 div cl mul cl mov edi, eax jmp .end .char: mov byte [esi + edi], al mov word [esi + edi + 1], 0xf add edi, 2 .end: mov dword [vb_pos], edi pop ecx pop esi pop eax pop edi ret ;;;;;;;;;;;;;;;;;;;;; ;print a null-terminated string ;;;;;;;;;;;;;;;;;;;;;; print_str: ;offset push ebp mov ebp, esp push esi push eax push edi mov esi, dword [ebp + 2 * 4] mov edi, 0xb8000 .loop_each_char: mov al, byte [esi] test al, al je .end call print_char inc esi jmp .loop_each_char .end: pop edi pop eax pop esi pop ebp ret ;;;;;;;;;;;;;;;;;;;;; ; helper function converting 4 bit val in al to its character ;;;;;;;;;;;;;;;;;;;;;; al_to_char: ; no parameters cmp al,09h jna .l2 add al,37h jmp .end .l2: add al,30h .end: ret