Advertisement
Il_Voza

4.4 AND between vectors & check if tot number of 1 is even

May 12th, 2013
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Write a program that executes an AND logic operation between elements of two vectors of byte, and that stores the result into a third vector. The program must also count parity elements even in the resultant vector, i.e. such that the number of 1 in the binary representation of number is even
  2.  
  3. DIM EQU 8
  4. .MODEL small
  5. .STACK
  6. .DATA
  7. v1 DB 1,0,1,1,0,0,0,0
  8. v2 DB 1,0,0,1,0,0,0,0
  9. v3 DB DIM DUP (?)
  10. .CODE
  11. .STARTUP
  12. MOV SI,0
  13. MOV CX,0
  14. MOV BX,0
  15. ciclo:
  16.        MOV AL,v1[SI]
  17.        AND AL,v2[SI]
  18.        MOV v3[SI],AL
  19.        CMP AL,1
  20.        JE counter
  21.        ciclo1:
  22.        INC SI
  23.        INC CX
  24.        CMP CX,DIM
  25.        JNE ciclo
  26.        JE even-odd
  27.  
  28. counter:
  29.           INC BX
  30.           JMP ciclo1
  31.          
  32. even-odd:
  33.      SHR BX,1   ;Here I divide by 2 the found number of 1 by the right shift, to see if it is divisible by 2. If it is divisible, it is even, if instead gives remainder, it is odd
  34.      JC odd ;If the CF gets up, means that I had remainder, so it is odd
  35.      JNC even
  36.      
  37. even: mov AH,2
  38.       MOV DL,'E' ;I print E to say "EVEN"
  39.       int 21h
  40.       JMP ex
  41.      
  42. odd: mov AH,2
  43.          MOV DL,'O' ;I print O to say "ODD"
  44.          int 21h
  45.          JMP ex
  46. ex:
  47. .exit
  48. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement