Guest User

Untitled

a guest
Nov 11th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. .code16
  2. .global _start
  3.  
  4. .equ STACK_SEGMENT, 0x7C00
  5. .equ ORG_SEGMENT, 0x0
  6.  
  7. .text
  8. _start:
  9. cli
  10. jmp $ORG_SEGMENT, $(asmain)
  11. asmain:
  12.  
  13. xor %ax, %ax
  14. mov %ax, %ds
  15. mov %ax, %es
  16. mov %ax, %ss
  17.  
  18. mov $STACK_SEGMENT, %esp
  19.  
  20. mov $0xDEAD, %ax
  21. call printRegister
  22. call putSeparator
  23.  
  24. mov $0xDEAD, %ax
  25. call printRegister
  26. call putSeparator
  27.  
  28. mov $0xDEAD, %ax
  29. call printRegister
  30. call putSeparator
  31.  
  32. mov $0xDEAD, %ax
  33. call printRegister
  34. call putSeparator
  35.  
  36. stop: jmp stop
  37.  
  38.  
  39.  
  40. printChar:
  41. mov $0xE, %ah # interrupt service
  42. mov $0x3, %bh # BH = page number = 0 ; BL = 3 = Cyan (ignored)
  43. int $0x10
  44. ret
  45.  
  46. putSeparator:
  47. mov $'_', %al
  48. call printChar
  49. ret
  50.  
  51. printRegister:
  52. test %ax, %ax # test for 0, that would
  53. jne .go
  54. mov $'0', %al
  55. call printChar
  56. ret
  57.  
  58. .go:
  59. mov $10, %bx
  60. xor %cx, %cx # number of elements pushed.
  61. xor %dx, %dx # high part of dividend
  62. .loop:
  63. div %bx # result = %AX ; remaineder = %DX
  64.  
  65. # we're not done yet:
  66. # Increment n. of elements
  67. add $1, %cx # elements to show
  68.  
  69. add $0x30, %dx # convert to ASCII
  70. push %dx
  71.  
  72. test %ax, %ax # should we continue?
  73. je .show
  74.  
  75. # Prepare %AX for next divs.
  76. xor %dx, %dx
  77. jmp .loop
  78.  
  79. .show:
  80. pop %dx
  81.  
  82. mov %dl, %al # load character -- already printable
  83. call printChar
  84.  
  85. sub $1, %cx
  86. test %cx, %cx
  87. jnz .show
  88.  
  89. ret
  90.  
  91. .space 510 - (. - _start)
  92. .word 0xaa55
Advertisement
Add Comment
Please, Sign In to add comment