Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. ; multi-segment executable file template
  2. ; Nathan Frazier HW 5 - 6
  3.  
  4. ; 10h-2 {DH=row}{DL=column}
  5. ; 0710:0000 entry point
  6. data segment ; ULR, ULC, BRR, BRC
  7. boxes db 5,10,20,70 ; first box
  8. db 08h
  9.  
  10. db 12,20,18,60 ; second box
  11. db 0Ch ; light green
  12.  
  13. db 1,5,3,10 ; third box
  14. db 0Dh
  15.  
  16. db 5,60,24,79 ; fourth box
  17. db 0Ah
  18.  
  19. db 5,25,18,75 ; fifth box
  20. db 0Eh
  21.  
  22. ; declare temp variables
  23. boxtally db 0
  24. ULrow db ?
  25. ULcol db ?
  26. BRrow db ?
  27. BRcol db ?
  28. ccode db ? ; COLOR CODE
  29.  
  30. ends
  31.  
  32. stack segment
  33. dw 128 dup(0)
  34. ends
  35.  
  36. code segment
  37. start:
  38. ; set segment registers:
  39. mov ax, data
  40. mov ds, ax
  41. mov es, ax
  42.  
  43. ; add your code here
  44.  
  45.  
  46. lea si, boxes ; set SI to starting memory address for table 'boxes'
  47. ; Label a function that pushes the next 4 values to the stack ( CL, RW, CL, RW )
  48. ; When needed pop these 4 values off the stack before reading in 4 more
  49. ; They will pop off the stack in the order: BRC BRR ULC ULR
  50.  
  51. CHECK:
  52. cmp boxtally, 5
  53. je THEEND ; if 5 boxes have been drawn, jump to end Else
  54.  
  55.  
  56. ; 'STACKEM' needs to ALSO prep the memory then immediately go into DRAW label
  57. mov cx, 5
  58. STACKEM:
  59. ; first, check if we drew all boxes already
  60.  
  61. push [si]
  62. inc si
  63. loop STACKEM
  64.  
  65. ; Once the next 4 values are read, make temp copies that will be overwritten every STACKEM
  66. ; AX is 16 bit and BRcol is 8 bit which = error To sidestep this, AX register for db's is AL Use AL
  67.  
  68. pop ax
  69. mov ccode, al ; stores color code first since it went in last
  70. pop ax
  71. mov BRcol, al
  72. pop ax
  73. mov BRrow, al
  74. pop ax
  75. mov ULcol, al
  76. pop ax
  77. mov ULrow, al
  78.  
  79.  
  80. ; Data finished parsing from table, set to named temp variables to keep track of
  81.  
  82. ; BEGIN CURSOR PREP
  83. BOTTOMRIGHT:
  84.  
  85. mov ah, 2 ;set cursor 10h-2
  86. mov dl, BRcol ; Pop BRC into DL
  87. mov dh, BRrow ; Pop BRR into DH
  88.  
  89. int 10h ; execute cursor move
  90. ; WRITE CHAR bottom right corner
  91. mov ah, 09h ; write char no attrib
  92. mov cx, 1 ;print the corner in bottom right once
  93. mov al, 217 ; ascii
  94. mov bl, ccode
  95.  
  96. int 10h ; execute char write
  97.  
  98.  
  99. ; BEGIN RIGHT EDGE DRAW
  100. REDGE:
  101.  
  102. cmp dh, ULrow ; see if cursor has reached upper row value
  103. je RC ; if it has, jump out! Else, continue
  104.  
  105. mov ah, 2 ;set cursor 10h-2
  106. dec dh ; decrement, cursor will jump up 1 line above the B R corner
  107. int 10h ; executes the row jump
  108.  
  109. mov ah, 09h ; write char no attrib 10h-0Ah
  110. mov al, 179 ; ascii vertical line
  111. mov bl, ccode
  112. int 10h ; execute char write
  113.  
  114.  
  115. jmp REDGE ; repeat, LOOPS INFINITELY UNTIL DH = STARTING ROW
  116.  
  117. RC: ; draw top right corner
  118. mov ah, 09h
  119. mov al, 191
  120. mov bl, ccode
  121. int 10h
  122.  
  123. ; END RIGHT EDGE DRAW, move cursor up one more and place upper right corner ascii then start from bottom left, rinse, repeat
  124. ; bottom left edge (row, col) = BRrow, ULcol - since row remains constant for entire bottom
  125. ;CURSOR PREP
  126. mov ah, 2 ;set cursor 10h-2
  127. mov dh, BRrow
  128. mov dl, ULcol
  129.  
  130. int 10h
  131.  
  132. mov ah, 09h ; write char no attrib
  133. mov cx, 1 ; loop factor
  134. mov al, 192 ; ascii L L corner char
  135. mov bl, ccode
  136.  
  137. int 10h ; execute char write 10h-0Ah
  138. ; while the cursor is already at bottom left, decrement to send it up the rows until it hits top row
  139. ; BEGIN LEFT EDGE DRAW
  140. LEDGE:
  141.  
  142. cmp dh, ULrow ; see if cursor has reached top row
  143. je ELE ; if it has, jump out! Else, continue
  144.  
  145. mov ah, 2
  146. dec dh ; decrement, cursor will jump up 1 above the B L corner
  147. int 10h ; executes the row jump
  148.  
  149. mov ah, 09h ; write char no attrib
  150. mov al, 179 ; ascii vertical line
  151. mov bl, ccode
  152. int 10h ; execute 10h - 0Ah
  153.  
  154.  
  155. jmp LEDGE ; repeat, LOOPS INFINITELY UNTIL DH = STARTING ROW
  156.  
  157. ; END LEFT EDGE DRAW
  158. ELE:
  159. ; cursor is coming in already @ ULrow
  160. ; draw top edge until cursor hits BRcol aka the rightmost column val
  161.  
  162. ; write upper left corner char then move cursor + 1 col
  163. mov ah, 09h
  164. mov al, 218
  165. mov bl, ccode
  166. mov cx, 1
  167. int 10h ;print the corner in upper left
  168.  
  169. mov ah, 02h ; it would erase the corner without these 2 line
  170. inc dl
  171. int 10h
  172.  
  173. ;BEGIN TOP EDGE DRAW
  174. TEDGE:
  175. mov ah, 03h ; return current cursor row to DH col to DL
  176. int 10h
  177.  
  178. cmp dl, BRcol
  179. je BECP ; jump to bottom edge label if cursor col = rightmost col
  180. ;else
  181. mov ah, 09h ; print char, advance cursor horizontally
  182. mov al, 196
  183. mov bl, ccode
  184. mov cx, 1
  185. int 10h
  186.  
  187. mov ah, 02h ; increment right
  188. inc dl
  189. int 10h
  190.  
  191. jmp TEDGE ; repeat until cursor col = rightmost col
  192.  
  193. ; BEGIN BOTTOM EDGE CURSOR PREP
  194. BECP:
  195.  
  196. mov ah, 02h
  197. mov dl, ULcol
  198. inc dl
  199. mov dh, BRrow
  200. int 10h ; execute set
  201.  
  202. ; BEGIN BOTTOM EDGE DRAW
  203. BEDGE:
  204. mov ah, 03h ; return current cursor row to DH col to DL
  205. int 10h
  206.  
  207. cmp dl, BRcol ; see if cursor has reached top row
  208. je TALLY ; BOX SHOULD BE FINISHED!!! exit the loop and add 1 victory to the tally variable
  209.  
  210. mov ah, 09h ; write char no attrib
  211. mov al, 196
  212. mov bl, ccode
  213. mov cx, 1
  214. int 10h
  215.  
  216. mov ah, 02h
  217. inc dl
  218. int 10h
  219.  
  220. jmp BEDGE ; repeat, LOOPS INFINITELY UNTIL DH = STARTING ROW
  221.  
  222.  
  223. TALLY:
  224. add boxtally, 1
  225. jmp CHECK ; go check the tally
  226.  
  227. THEEND:
  228. ; wait for any key
  229. mov ah, 1
  230. int 21h
  231.  
  232. mov ax, 4c00h ; exit to operating system
  233. int 21h
  234. ends
  235.  
  236. end start ; set entry point and stop the assembler
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement