/asm/boot/test/console.s

http://github.com/dennis-gemini/tests · Assembly · 176 lines · 155 code · 21 blank · 0 comment · 0 complexity · eeade27587de69822e4409188ed01693 MD5 · raw file

  1. .code16
  2. .text
  3. #############################################
  4. #
  5. # print string
  6. #
  7. # input:
  8. # %ds:%si = asciiz string
  9. #
  10. #############################################
  11. .global print
  12. print:
  13. push %ax
  14. push %si
  15. 1:
  16. lodsb
  17. orb %al, %al
  18. jz 2f
  19. mov $0x0e, %ah
  20. int $0x10
  21. jmp 1b
  22. 2:
  23. pop %si
  24. pop %ax
  25. ret
  26. #############################################
  27. #
  28. # print one character
  29. #
  30. # input:
  31. # %al = ascii
  32. #
  33. #############################################
  34. .global putchar
  35. putchar:
  36. push %ax
  37. mov $0x0e, %ah
  38. int $0x10
  39. pop %ax
  40. ret
  41. .if 0
  42. #############################################
  43. #
  44. # print integer in hexdecimal string
  45. #
  46. # input:
  47. # %ax = integer
  48. #
  49. #############################################
  50. .global print_hex
  51. print_hex:
  52. push %ax
  53. push %cx
  54. push %si
  55. mov $(str_hex_prefix), %si
  56. call print
  57. mov %ax, %si
  58. mov $4, %cx
  59. 1:
  60. shl $4, %si
  61. shr $12, %ax
  62. call to_hex_char
  63. call putchar
  64. mov %si, %ax
  65. loopnz 1b
  66. pop %si
  67. pop %cx
  68. pop %ax
  69. ret
  70. to_hex_char:
  71. add $'0', %al
  72. cmp $'9', %al
  73. jbe 1f
  74. add $('a' - ('9' + 1)), %al
  75. 1:
  76. ret
  77. str_hex_prefix: .ascii " 0x\0"
  78. .endif
  79. #############################################
  80. #
  81. # print integer in decimal string
  82. #
  83. # input:
  84. # %ax = integer
  85. #
  86. #############################################
  87. .global print_dec
  88. print_dec:
  89. push %ax
  90. push %bx
  91. push %cx
  92. push %dx
  93. mov $4, %cx
  94. mov $divisors_of_tens, %bx
  95. 1:
  96. xor %dx, %dx
  97. divw (%bx)
  98. or %ax, %ax
  99. jz 2f
  100. add $'0', %al
  101. call putchar
  102. 2:
  103. mov %dx, %ax
  104. add $2, %bx
  105. loopnz 1b
  106. add $'0', %al
  107. call putchar
  108. mov $'\r', %al
  109. call putchar
  110. mov $'\n', %al
  111. call putchar
  112. pop %dx
  113. pop %cx
  114. pop %bx
  115. pop %ax
  116. ret
  117. divisors_of_tens: .short 10000, 1000, 100, 10
  118. #############################################
  119. #
  120. # show the rolling bar at cursor
  121. #
  122. #############################################
  123. .if 0
  124. .global step_it
  125. step_it:
  126. push %ax
  127. push %bx
  128. push %cx
  129. push %si
  130. mov $str_msg_step, %si
  131. mov $str_cur_step, %bx
  132. movb (%si), %al
  133. mov $4, %cx
  134. 1:
  135. cmpb %al, (%bx)
  136. jz 2f
  137. inc %bx
  138. loopnz 1b
  139. jmp 3f
  140. 2:
  141. sub $str_cur_step, %bx
  142. add $str_next_step, %bx
  143. movb (%bx), %al
  144. movb %al, (%si)
  145. call print
  146. 3:
  147. pop %si
  148. pop %cx
  149. pop %bx
  150. pop %ax
  151. ret
  152. str_cur_step: .ascii "\\|/-"
  153. str_next_step: .ascii "|/-\\"
  154. str_msg_step: .ascii "\\\b\0"
  155. .endif