Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;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
- DIM EQU 8
- .MODEL small
- .STACK
- .DATA
- v1 DB 1,0,1,1,0,0,0,0
- v2 DB 1,0,0,1,0,0,0,0
- v3 DB DIM DUP (?)
- .CODE
- .STARTUP
- MOV SI,0
- MOV CX,0
- MOV BX,0
- ciclo:
- MOV AL,v1[SI]
- AND AL,v2[SI]
- MOV v3[SI],AL
- CMP AL,1
- JE counter
- ciclo1:
- INC SI
- INC CX
- CMP CX,DIM
- JNE ciclo
- JE even-odd
- counter:
- INC BX
- JMP ciclo1
- even-odd:
- 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
- JC odd ;If the CF gets up, means that I had remainder, so it is odd
- JNC even
- even: mov AH,2
- MOV DL,'E' ;I print E to say "EVEN"
- int 21h
- JMP ex
- odd: mov AH,2
- MOV DL,'O' ;I print O to say "ODD"
- int 21h
- JMP ex
- ex:
- .exit
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement