fork download
  1. .model small,c
  2.  
  3. public current_x, current_y, current_attr
  4.  
  5. .stack
  6.  
  7. .data
  8. current_x db 0
  9. current_y db 0
  10. current_attr db 0
  11. columns db 0
  12.  
  13. .code
  14. gotoxy proc
  15. mov current_x, al
  16. mov current_y, ah
  17. ret
  18. gotoxy endp
  19.  
  20. getx proc
  21. mov al,current_x
  22. ret
  23. getx endp
  24.  
  25. gety proc
  26. mov al,current_y
  27. ret
  28. gety endp
  29.  
  30. getattr proc
  31. mov al,current_attr
  32. ret
  33. getattr endp
  34.  
  35. setattr proc
  36. mov current_attr, al
  37. ret
  38. setattr endp
  39.  
  40. setbackground proc
  41. mov ah,current_attr
  42. and ah,0fh
  43. mov cl, 4
  44. shl al, cl
  45. or ah,al
  46. mov current_attr, ah
  47. ret
  48. setbackground endp
  49.  
  50. setforeground proc
  51. and al, 0fh
  52. mov ah, current_attr
  53. and ah, 0f0h
  54. or ah, al
  55. mov current_attr, ah
  56. ret
  57. setforeground endp
  58.  
  59. putstring proc uses es di
  60. ; call with ds:si = address of ASCIIZ string to print out.
  61. ; uses: di, cx, dx
  62. ; The following section takes a pair of coordinates and figures
  63. ; out their address.
  64.  
  65. mov cx,0b000h ; First get the video buffer segment.
  66. mov ah, 0fh
  67. int 10h
  68. mov columns,ah
  69. cmp al, 7
  70. jz @f
  71. mov cx, 0b800h
  72. @@:
  73. mov es,cx
  74.  
  75. mov al,current_y
  76. mov dl,ah
  77. mul dl
  78. mov di,ax
  79. mov al,current_x
  80. cbw
  81. add di,ax
  82. shl di, 1
  83.  
  84. ; This next bit actually writes the string to the screen.
  85. mov ah,current_attr
  86. lodsb
  87. @@:
  88. stosw
  89. lodsb
  90. test al,al
  91. jnz @b
  92.  
  93. ; This converts the final address back to a pair of coordinates
  94. ; and stores them so the next string will immediately follow this
  95. ; one if the current position isn't repositioned beforehand.
  96. mov dl, columns
  97. div dl
  98. mov current_y, al
  99. mov current_x, ah
  100. done:
  101. ret
  102. putstring endp
  103.  
  104. ifdef DOTEST
  105.  
  106. .data
  107. string1 db "This is blue on green.", 0
  108. string2 db "This is green on blue.", 0
  109.  
  110. .code
  111. .startup
  112. main proc
  113. mov al, 21h
  114. call setattr
  115. xor ax, ax
  116. call gotoxy
  117. mov si, offset string1
  118. call putstring
  119.  
  120. mov al, 12h
  121. call setattr
  122. mov ax, 0100h
  123. call gotoxy
  124. mov si, offset string2
  125. call putstring
  126. xor ax, ax
  127. int 16h
  128. mov ax, 4c00h
  129. int 21h
  130. main endp
  131. endif
  132.  
  133. end
  134.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.asm:1: error: attempt to define a local label before any non-local labels
prog.asm:1: error: parser: instruction expected
prog.asm:3: error: parser: instruction expected
prog.asm:14: error: parser: instruction expected
prog.asm:18: error: symbol `gotoxy' redefined
prog.asm:18: error: parser: instruction expected
prog.asm:20: error: parser: instruction expected
prog.asm:23: error: symbol `getx' redefined
prog.asm:23: error: parser: instruction expected
prog.asm:25: error: parser: instruction expected
prog.asm:28: error: symbol `gety' redefined
prog.asm:28: error: parser: instruction expected
prog.asm:30: error: parser: instruction expected
prog.asm:33: error: symbol `getattr' redefined
prog.asm:33: error: parser: instruction expected
prog.asm:35: error: parser: instruction expected
prog.asm:38: error: symbol `setattr' redefined
prog.asm:38: error: parser: instruction expected
prog.asm:40: error: parser: instruction expected
prog.asm:48: error: symbol `setbackground' redefined
prog.asm:48: error: parser: instruction expected
prog.asm:50: error: parser: instruction expected
prog.asm:57: error: symbol `setforeground' redefined
prog.asm:57: error: parser: instruction expected
prog.asm:59: error: parser: instruction expected
prog.asm:87: error: symbol `@@' redefined
prog.asm:102: error: symbol `putstring' redefined
prog.asm:102: error: parser: instruction expected
prog.asm:104: error: parser: instruction expected
prog.asm:112: error: parser: instruction expected
prog.asm:117: error: comma, colon or end of line expected
prog.asm:124: error: comma, colon or end of line expected
prog.asm:130: error: symbol `main' redefined
prog.asm:130: error: parser: instruction expected
stdout
Standard output is empty