Docsity

Assignment 3 Solutions - Microprocessor Systems | EE 3750, Assignments of Electrical and Electronics Engineering

Toggle sidebar
bg1
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
pf2

Partial preview of the text

Download Assignment 3 Solutions - Microprocessor Systems | EE 3750 and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

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

EE 3750 — Trahan HW solutions 2

  1. Write an 8086 instruction sequence to use program-controlled I/O to input 250 words and store them in array gray. Let indev denote the input device. The status port for indev is a byte port at address 5E36H; bit 4 is the ready bit. The data port for indev is a word port at address 5E34H. MOV SI, 0 ; pointer into array gray NEXT: MOV DX, 5E36H ; use DX to hold port addresses because longer than 8 bits CKIN: IN AL, DX ; input status TEST AL, 10000B ; poll ready bit JZ CKIN MOV DX, 5E34H IN AX, DX ; input data MOV GRAY[SI], AX ; store data in gray ADD SI, 2 ; update pointer CMP SI, 500 ; check if finished — starting from 0, SI holds 500 after inputting and storing 250th word JB NEXT
  2. Write an 8086 instruction sequence to initialize an 82C55 programmable peripheral interface. Set Group A to operate in Mode 2. Set Group B to operate in Mode 1 with Port B as an input port. Let 90H be the lowest port address for this 82C55. MOV AL, 11000110B ; 11xxx11x OUT 93H, AL ; two lowest bits of command register address = 11