25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
2.9 KiB

5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
5 년 전
  1. void print(string);
  2. void* dump_ax_return(input);
  3. void print(string)
  4. char* string;
  5. {
  6. #asm
  7. push bp
  8. mov bp,sp
  9. mov si,4[bp]
  10. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11. new_print_print:
  12. ; Prints string in si
  13. ; IN si: zero terminated string to print
  14. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15. mov ah, #0xE ; Specify 'int 0x10' 'teletype output' function
  16. ; [AL = Character, BH = Page Number, BL = Colour (in graphics mode)]
  17. .new_print_printchar:
  18. lodsb ; Load byte at address SI into AL, and increment SI
  19. test al, al
  20. jz .new_print_done ; If the character is zero (NUL), stop writing the string
  21. int #0x10 ; Otherwise, print the character via 'int 0x10'
  22. jmp .new_print_printchar ; Repeat for the next character
  23. .new_print_done:
  24. pop bp
  25. #endasm
  26. }
  27. void print_stack(argument)
  28. {
  29. #asm
  30. push bp
  31. mov bp,sp
  32. push ds
  33. push ax
  34. mov ax, ss
  35. mov ds, ax
  36. mov si,4[bp]
  37. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  38. print_stack_print:
  39. ; Prints string in si
  40. ; IN si: zero terminated string to print
  41. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  42. mov ah, #0xE ; Specify 'int 0x10' 'teletype output' function
  43. ; [AL = Character, BH = Page Number, BL = Colour (in graphics mode)]
  44. .print_stack_printchar:
  45. lodsb ; Load byte at address SI into AL, and increment SI
  46. test al, al
  47. jz .print_stack_done ; If the character is zero (NUL), stop writing the string
  48. int #0x10 ; Otherwise, print the character via 'int 0x10'
  49. jmp .print_stack_printchar ; Repeat for the next character
  50. .print_stack_done:
  51. pop ax
  52. pop ds
  53. pop bp
  54. #endasm
  55. }
  56. void* dump_ax_return(input)
  57. void* input;
  58. {
  59. return input;
  60. }
  61. void dump_ax(input)
  62. void* input;
  63. {
  64. dump_ax_return(input)
  65. #asm
  66. push bp
  67. mov bp,sp
  68. pusha ; save registers
  69. mov bx, ax
  70. mov ah, #0xE ; Teletype output
  71. mov cx, #4 ; 4 nipples in a 16 bit word
  72. .dump_ax_loop:
  73. rol bx, #4 ; rotate to next nipple
  74. mov al, bl ; we copy to al because we need to mask only the low 4 bits
  75. and al, #%1111 ; Do the masking
  76. add al, #48 ; convert to ASCII
  77. cmp al, #57 ; If we are greater than 9 ascii, we add 7 to make digit 10 be represented as 'A'
  78. jbe .dump_ax_skip ; -|-
  79. add al, #7 ; -|-
  80. .dump_ax_skip: ; -|-
  81. int #0x10 ; BIOS call 'output'
  82. loop .dump_ax_loop
  83. popa ; restore registers
  84. pop bp
  85. #endasm
  86. }
  87. void print_newline()
  88. {
  89. #asm
  90. printCRLF:
  91. mov ah, #0xE
  92. mov al, #13
  93. int #0x10
  94. mov al, #10
  95. int #0x10
  96. ret
  97. #endasm
  98. }