EE 3750 — Trahan HW solutions 1
EE 3750 — Trahan Homework solutions
Spring 2010
1. Let yellow be a byte variable. Write an 8086 instruction sequence to complement bits
0 and 1, force bits 5 and 7 to 1, then do the following. If bit 4 of yellow is 0, then copy yellow to
register AH; if bit 4 is 1, then copy yellow to register BH.
XOR YELLOW, 11B ; complement bits 0 and 1
OR YELLOW 10100000B ; for bits 5 and 7 to 1
TEST YELLOW, 10000B ; check bit 4
JNZ ONE ; jump to label ONE if bit 4 is 1
MOV AH, YELLOW ; copy yellow to AH if bit 4 is 0
JMP DONE ; jump over case where bit 4 is 1
ONE: MOV BH, YELLOW ; copy yellow to BH if bit 4 is 1
DONE:
2. The NEO protocol for preventing cheating in peer-to-peer online games includes a
step in which a player sends a bit vector of votes on whether other players’ updates were
received on time. Write an 8086 instruction sequence to build a bit vector in the following
manner. You are given array votes with size elements (assume 1 ≤ size ≤ 8) such that each
element of votes is an integer in the range from 0 to 7. (If an element of votes is 5, then this is a
positive vote on Player 5.) Create a bit vector in register DL with a 1 in the corresponding
position for each positive vote and zeroes in all other positions. Assume that votes is a byte
variable and size is a word variable.
Example: Suppose votes contains size = 3 elements with values 5, 0, and 2. Then the
binary contents of register DL should be 00100101.
MOV BX, 0 ; pointer into array votes
MOV DL, 0 ; initialize DL to 0
TOP: MOV DH, 1 ; initialize DH
MOV CL, VOTES[BX] ; CL holds shift distance
SHL DH, CL ; move the 1 in DH into the position specified by
this element of votes
OR DL, DH ; insert this vote into DL
INC BX ; update pointer
CMP BX, SIZE ; check if finished
JB TOP