Guest User

Untitled

a guest
Apr 24th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. org 7C00h
  2.  
  3. global Print ; allow everything to access Print
  4. jmp Start ; skip the data
  5.  
  6. MTest: db "This is a test string! "
  7. EMTest:
  8. MTest2: db "This is another test string! "
  9. EMTest2:
  10.  
  11. Start:
  12. mov bx, 000Fh ; Page 0, color attribute 15 (white) for the int 10 calls below
  13. mov cx, 1 ; We will write 1 char
  14. xor dx, dx ; Start at top-left corner
  15. mov ds, dx ; Ensure ds = 0 (to let us load the message)
  16. cld ; Ensure direction flag is cleared for LODSB
  17.  
  18. push EMTest ; Push EMTest (end of MTest) onto the stack
  19. push MTest ; Push MTest onto the stack
  20. call Print ; Call `Print`
  21. add esp, 2
  22.  
  23. push EMTest2 ; Push EMTest2 (end of MTest2) onto the stack
  24. push MTest2 ; Push MTest2 onto the stack
  25. call Print ; Call `Print`
  26. add esp, 2
  27.  
  28. jmp Halt ; Halt system
  29.  
  30. Print:
  31. push ebp
  32. mov ebp, esp
  33. mov si, [ebp+6] ; Pops the beginning of the string into si
  34. mov di, [ebp+8] ; Pop end of string into eax
  35.  
  36. PrintChar:
  37. mov ah, 2 ; PC BIOS Interrupt 10 Subfunction 2 - Set cursor position
  38. ; AH = 2
  39. ; BH = page, DH = row, DL = column
  40. int 10h
  41. lodsb ; Loads a byte of the message into AL.
  42. ; DS is 0 and SI holds the offset of one of the bytes of the message
  43.  
  44. mov ah, 9 ; PC BIOS Interrupt 10 subfunction 9 - write character and color
  45. ; AH = 9
  46. ; BH = page, AL = character, BL = attribute, CX = character count
  47. int 10h
  48.  
  49. inc dl ; Advance cursor
  50.  
  51. cmp dl, 80 ; Wrap around edge of screen if necessary (word-wrap)
  52. jne PrintChar.skip
  53. xor dl, dl ; Back to the first char of the line
  54. inc dh ; Next line!
  55.  
  56. cmp dh, 25 ; Wrap around bottom of the screen if necessary
  57. jne PrintChar.skip
  58. xor dh, dh
  59.  
  60. .skip:
  61. cmp si, di ; If we're not at end of message
  62. jne PrintChar ; continue loading characters
  63. mov esp, ebp
  64. pop ebp
  65. ret
  66.  
  67. Halt:
  68. cli ; Stop interrupts
  69. hlt ; Halt system
  70.  
  71. times 0200h - 2 - ($ - $$) db 0 ; Zerofill up to 510 bytes
  72.  
  73. dw 0AA55h ; Boot sector signature
Add Comment
Please, Sign In to add comment