Advertisement
obernardovieira

Draw a flag (which size you want) [Intel 8086]

Jun 16th, 2015
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .8086
  2. .model small
  3. .stack 2048
  4.  
  5. dseg    segment para public 'data'
  6.  
  7.     ;this is the total size of flag, but somewhere above, you will see that
  8.     ;I just decrement the left, right and middle column, and then
  9.     ;when I jump between them, I use that value, without subtract by 2
  10.     ;Remember, columns are "words" (theory) so, insted divide by 2 and multiply
  11.     ;again, I just leave it as it is
  12.  
  13.     ;total size
  14.     maxColumns  dw  69      ;includes left, right and middle columns
  15.     maxLines    dw  19      ;same with lines
  16.     toNextLine  dw  ?
  17.  
  18. dseg    ends
  19.  
  20. cseg    segment para public 'code'
  21. assume  cs:cseg, ds:dseg
  22.  
  23. Main  proc
  24.     mov ax, dseg
  25.     mov ds, ax
  26.     mov ax,0b800h       ;B800 is the video memory adress
  27.     mov es,ax           ;move that adress to es
  28.                         ;es stands for "extra segment"
  29.  
  30.     ;code to clear screen (shared before)
  31.     mov bx, ' '     ;space to bx. A space is what we will write in screen (to clean)
  32.     xor di, di      ;di -> 0
  33.     mov cx, 24*80   ;24*80 is the size of window! 24 lines,80 columns
  34.  
  35. clear:
  36.     mov es:[di], bx ;move the space to video adreess (in other words, write a space on screen)
  37.     add di, 2       ;every video adress have a size of word, so let's add 2
  38.     loop clear      ;repeat until cx = 0, In every loop, cx is decremented
  39.  
  40.  
  41.     ;draw the flag
  42.     mov bl, 00100000b       ;[0][010][0000]b -> binary (*see below)
  43.  
  44.  
  45.     mov bh, '*'             ;this is the char we will print
  46.     xor di, 320             ;the position we will start
  47.     xor si, 320             ;in this case we will start e second line
  48.  
  49.     mov cx, maxColumns      ;let's draw the top line
  50. theTop:
  51.     mov es:[si], bh
  52.     mov es:[si+1], bl
  53.     add si, 2
  54.     loop theTop             ;done!
  55.  
  56.  
  57.     mov cl, 2               ;now, calculate the middle line
  58.     mov ax, maxLines
  59.     dec ax
  60.     div cl                  ;and the result will be saved in ax
  61.  
  62.     sub maxLines, 2         ;subtract 2 lines (top and bottom)
  63.                             ;the middle line will be decremented after
  64.  
  65.     sub maxColumns, 3       ;decremente 3 columns (left, middle and right)
  66.     mov dx, maxColumns      ;save value in ax
  67.  
  68.  
  69.     mov toNextLine, 160     ;calculate ao much columns we need to jump
  70.     sub toNextLine, 6       ;until next line
  71.     sub toNextLine, dx
  72.     sub toNextLine, dx      ;the result will be in toNextLine
  73.  
  74.     add si, toNextLine      ;now, jump to next line, because um print the top
  75.                             ;but we have more to print
  76.  
  77. drawFlag:
  78.  
  79.     mov es:[si], bh         ;print left column
  80.     mov es:[si+1], bl
  81.  
  82.     add si, 2               ;jump this columns
  83.     add si, maxColumns      ;and the necessary number of columns until the middle
  84.  
  85.     mov es:[si], bh         ;print middle column
  86.     mov es:[si+1], bl
  87.  
  88.     add si, 2               ;again, jump to right column
  89.     add si, maxColumns
  90.  
  91.     mov es:[si], bh         ;print right column
  92.     mov es:[si+1], bl
  93.  
  94.     add si, 2
  95.     add si, toNextLine      ;add the number of columns until next line
  96.  
  97.     dec maxLines            ;decrement lines
  98.     cmp maxLines, ax        ;check if we are in the middle line
  99.     jne keepGoing           ;if not, keep print the flag
  100.  
  101.     mov cx, maxColumns      ;if yes, print the middle line
  102.     add cx, 3               ;add 3, because we decrement 3 before
  103. theMiddle:
  104.     mov es:[si], bh
  105.     mov es:[si+1], bl
  106.     add si, 2
  107.     loop theMiddle
  108.  
  109.     dec maxLines            ;after middle line is printed, decremente one line
  110.     add si, toNextLine      ;and jump to next line
  111. keepGoing:
  112.     cmp maxLines, 0         ;compare if we are in last line
  113.     jne drawFlag            ;if not, keep print the flag
  114.  
  115. ;++++++++++++++++
  116.     mov cx, maxColumns      ;and now, print the bottom line of flag
  117.     add cx, 3               ;add 3 again
  118. theTail:
  119.     mov es:[si], bh
  120.     mov es:[si+1], bl
  121.     add si, 2
  122.     loop theTail            ;done!
  123.  
  124.  
  125.     mov ah,4CH
  126.     int 21H
  127. main    endp
  128.  
  129. cseg    ends
  130. end     main
  131.  
  132. ;the first 0 means static, if 1, text will be blinking
  133. ;the next 3 digits is for brackground color [000-111]
  134. ;the next 4 digits is for text color [000-1111]
  135. ;colors
  136. ;black          0000
  137. ;blue           0001
  138. ;gren           0010
  139. ;cyan           0011
  140. ;red            0100
  141. ;magenta        0101
  142. ;brown          0110
  143. ;light grey     0111
  144. ;dark grey      1000
  145. ;light blue     1001
  146. ;light green    1010
  147. ;light cyan     1011
  148. ;light red      1100
  149. ;light magenta  1101
  150. ;yellow         1110
  151. ;white          1111
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement