Operating System


SUBMITTED BY: Guest

DATE: Oct. 12, 2013, 4:11 a.m.

FORMAT: Text only

SIZE: 1.7 kB

HITS: 1238

  1. dochar:
  2. call cprint ; print one character
  3. sprint:
  4. mov eax, [esi] ; string char to AL
  5. lea esi, [esi+1]
  6. cmp al, 0
  7. jne dochar ; else, we're done
  8. add byte [ypos], 1 ; down one row
  9. mov byte [xpos], 0 ; back to left
  10. ret
  11. cprint:
  12. mov ah, 0x0F ; attrib = white on black
  13. mov ecx, eax ; save char/attribute
  14. movzx eax, byte [ypos]
  15. mov edx, 160 ; 2 bytes (char/attrib)
  16. mul edx ; for 80 columns
  17. movzx ebx, byte [xpos]
  18. shl ebx, 1 ; times 2 to skip attrib
  19. mov edi, 0xb8000 ; start of video memory
  20. add edi, eax ; add y offset
  21. add edi, ebx ; add x offset
  22. mov eax, ecx ; restore char/attribute
  23. mov word [ds:edi], ax
  24. add byte [xpos], 1 ; advance to right
  25. ret
  26. ;------------------------------------
  27. printreg32:
  28. mov edi, outstr32
  29. mov eax, [reg32]
  30. mov esi, hexstr
  31. mov ecx, 8 ; eight nibbles
  32. hexloop:
  33. rol eax, 4 ; leftmost will
  34. mov ebx, eax ; become rightmost
  35. and ebx, 0x0f ;
  36. mov bl, [esi + ebx] ; index into hexstr
  37. mov [edi], bl
  38. inc edi
  39. dec ecx
  40. jnz hexloop
  41. mov esi, outstr32
  42. call sprint
  43. ret
  44. ;------------------------------------
  45. xpos db 0
  46. ypos db 0
  47. hexstr db '0123456789ABCDEF'
  48. outstr32 db '00000000', 0 ; register value
  49. reg32 dd 0 ; pass values to printreg32

comments powered by Disqus