SteveOS for 16 bit processors (286)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

109 lines
1.6 KiB

  1. ;; ax - number in
  2. print_hex:
  3. pusha
  4. mov [hex_count], byte 0
  5. print_hex_digit:
  6. mov dx, 0
  7. mov bx, 16
  8. div bx ;ax/16
  9. ;; dx = remainder
  10. ;; ax = answer
  11. push ax
  12. cmp dx, 9
  13. jg hex_digit ;A-F
  14. add dl, '0'
  15. mov bx, hex_buffer
  16. add bx, [hex_count]
  17. mov [bx], dl
  18. add [hex_count], byte 1
  19. jmp print_hex_next
  20. hex_digit:
  21. add dl, 0x37
  22. mov bx, hex_buffer
  23. add bx, [hex_count]
  24. mov [bx], dl
  25. add [hex_count], byte 1
  26. ;;jmp print_hex_digit
  27. print_hex_next:
  28. pop ax
  29. cmp ax, 0
  30. jg print_hex_digit ;more digits
  31. ;; add '0x'
  32. mov al, '0'
  33. call print_char
  34. mov al, 'x'
  35. call print_char
  36. ;; output buffer... in reverse
  37. mov bx, hex_buffer
  38. add bx, [hex_count]
  39. output_digit:
  40. sub bx, 1
  41. mov al, [bx]
  42. call print_char
  43. sub [hex_count], byte 1
  44. cmp [hex_count], byte 0
  45. jne output_digit
  46. ;; done
  47. popa
  48. ret
  49. ;;;END print hex
  50. hex_buffer: times 5 db 0
  51. hex_count: dw 0
  52. ;; Pass pointer to string @bx
  53. ;; Pass colour into cx
  54. print:
  55. pusha
  56. mov ah, 0x0E ;Teletype output
  57. print_cont:
  58. mov al, [bx]
  59. cmp al, 0
  60. je print_end
  61. xchg cx, bx
  62. int 0x10 ;print the character
  63. xchg bx, cx
  64. inc bx
  65. jmp print_cont ;One less instruction per print
  66. print_end:
  67. popa
  68. ret
  69. ;; Pass character @al
  70. print_char:
  71. pusha
  72. mov ah, 0x0E
  73. int 0x10
  74. popa
  75. ret
  76. ;; Prints an array of strings
  77. ;; bx - array of pointers to strings
  78. ;; al - char to print out between strings
  79. print_array:
  80. pusha
  81. print_array_cont:
  82. cmp [bx], word 0
  83. je print_array_done
  84. push bx
  85. mov bx, [bx]
  86. call print
  87. pop bx
  88. ;; al is already set
  89. call print_char
  90. add bx, 2
  91. jmp print_array_cont
  92. print_array_done:
  93. popa
  94. ret