Advertisement
obernardovieira

Write pair/odd numbers in diferent lines [Intel 8086]

Jun 16th, 2015
591
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.     myvector    db  "6","2","3","4",0
  7.     numbers     dw  4   ;we will calculate 4 numbers (6,2,3 and 4)
  8. dseg    ends
  9.  
  10. cseg    segment para public 'code'
  11. assume  cs:cseg, ds:dseg
  12.  
  13. Main  proc
  14.     mov ax, dseg
  15.     mov ds, ax
  16.     mov ax,0b800h       ;B800 is the video memory adress
  17.     mov es,ax           ;move that adress to es
  18.                         ;es stands for "extra segment"
  19.  
  20.     mov cx, numbers     ;how much numbers we will calculate?
  21.     mov dl, 0           ;dl will be used to know, how much cells we used in second line
  22.     mov dh, 2           ;we will divide by two, to verify if it's pair or not
  23.  
  24.     xor di, di
  25.     mov si, 15*160      ;this is to where we will put the text. Line 15
  26. ciclo:
  27.     mov bh, myvector[di];get the text from screen
  28.  
  29.     mov al, bh
  30.     mov ah, 0           ;ah has zero because we will divide ax
  31.     div dh              ;ax / dh -> ah:al
  32.     cmp ah, 0           ;if number is par, the rest is zero
  33.     jne impar           ;otherwise odd
  34.  
  35. ;pair:
  36.     mov bl, 00100000b   ;[0][010][0000]b -> binary (*see below)
  37.     mov es:[si], bh     ;move the space to video adreess (in other words, write a space on screen)
  38.     mov es:[si+1], bl   ;change color
  39.     add si, 2
  40.     jmp goAhead
  41.  
  42. impar:
  43.  
  44.     mov ax, si          ;save what is in si (we will use si)
  45.     mov dh, 0           ;zero to dh because we will use dx, but just want dl
  46.  
  47.     mov si, 16*160      ;line 16
  48.     add si, dx          ;move to the first unset cell
  49.  
  50.     mov bl, 01000000b   ;[0][100][0000]b -> binary (*see below)
  51.     mov es:[si], bh     ;move the space to video adreess (in other words, write a space on screen)
  52.     mov es:[si+1], bl   ;change color
  53.  
  54.     add dl, 2           ;
  55.     mov dh, 2           ;return the two, to make divisions
  56.     mov si, ax          ;return to si his value
  57.  
  58.  
  59. goAhead:
  60.     inc di              ;every video adress have a size of word, so let's add 2
  61.  
  62.     loop ciclo          ;repeat until cx = 0, In every loop, cx is decremented
  63.  
  64.     mov ah,4CH
  65.     int 21H
  66. main    endp
  67.  
  68. cseg    ends
  69. end     main
  70.  
  71. ;the first 0 means static, if 1, text will be blinking
  72. ;the next 3 digits is for brackground color [000-111]
  73. ;the next 4 digits is for text color [000-1111]
  74. ;colors
  75. ;black          0000
  76. ;blue           0001
  77. ;gren           0010
  78. ;cyan           0011
  79. ;red            0100
  80. ;magenta        0101
  81. ;brown          0110
  82. ;light grey     0111
  83. ;dark grey      1000
  84. ;light blue     1001
  85. ;light green    1010
  86. ;light cyan     1011
  87. ;light red      1100
  88. ;light magenta  1101
  89. ;yellow         1110
  90. ;white          1111
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement