Docsity

EE 3750 — Test 1 Solutions: Instruction Execution and Protocol Implementation - Prof. J. T, Exams of Electrical and Electronics Engineering

Toggle sidebar
bg1
EE 3750 — Test 1 solutions 1
EE 3750 — Test 1 solutions
Fall 2009
1. (20 pts) Given the register and memory contents listed below, do the following for the
instruction ADD BX, [DI+9]:
(a) identify the addressing mode of the memory operand,
(b) give the effective address of the memory operand,
(c) show the contents of the destination operation after the addition,
(d) give the flag settings for CF, PF, AF, ZF, SF, and OF after the addition, and
(e) specify how many memory reads and memory writes are performed.
Contents: All integer contents are written in hexadecimal. Let BX = A2E1, DI = 5C00,
and let each byte in memory hold 18.
(a) register relative
(b) effective address = 5C09 (= 5C00 + 9)
(c) BX = BAF9 (= A2E1 + 1818)
(d) CF = 0, PF = 1, AF = 0, ZF = 0, SF = 1, OF = 0
(e) 1 memory read, 0 memory writes
2. (30 pts) Write 8086 assembly language instruction sequences to implement the
equation below, making the specified assumption about data types in (a), (b), and (c).
blue !black "green
( )
#white
yellow
(a) all variables are signed words,
(b) all variables are unsigned words, and
(c) all variables are unsigned bytes.
(a)
MOV AX, BLACK ; one operand of word multiplication must be in AX
IMUL GREEN ; IMUL because signed; product in DX—AX
MOV BX, AX ; store product so that can sign-extend white
MOV CX, DX
MOV AX, WHITE
CWD ; DX—AX now holds 32-bit version of white
SUB BX, AX
SBB CX, DX ; subtract with borrow for high word
MOV AX, BX ; put difference back into DX—AX before division
MOV DX, CX
IDIV YELLOW ; IDIV because signed; quotient in AX
MOV BLUE, AX
pf3

Partial preview of the text

Download EE 3750 — Test 1 Solutions: Instruction Execution and Protocol Implementation - Prof. J. T and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

EE 3750 — Test 1 solutions

Fall 2009

  1. (20 pts) Given the register and memory contents listed below, do the following for the instruction ADD BX, [DI+9]: (a) identify the addressing mode of the memory operand, (b) give the effective address of the memory operand, (c) show the contents of the destination operation after the addition, (d) give the flag settings for CF, PF, AF, ZF, SF, and OF after the addition, and (e) specify how many memory reads and memory writes are performed. Contents: All integer contents are written in hexadecimal. Let BX = A2E1, DI = 5C00, and let each byte in memory hold 18. (a) register relative (b) effective address = 5C09 (= 5C00 + 9) (c) BX = BAF9 (= A2E1 + 1818) (d) CF = 0, PF = 1, AF = 0, ZF = 0, SF = 1, OF = 0 (e) 1 memory read, 0 memory writes
  2. (30 pts) Write 8086 assembly language instruction sequences to implement the equation below, making the specified assumption about data types in (a), (b), and (c). blue!

( black^ "^ green ) #^ white

yellow (a) all variables are signed words, (b) all variables are unsigned words, and (c) all variables are unsigned bytes. (a) MOV AX, BLACK ; one operand of word multiplication must be in AX IMUL GREEN ; IMUL because signed; product in DX—AX MOV BX, AX ; store product so that can sign-extend white MOV CX, DX MOV AX, WHITE CWD ; DX—AX now holds 32-bit version of white SUB BX, AX SBB CX, DX ; subtract with borrow for high word MOV AX, BX ; put difference back into DX—AX before division MOV DX, CX IDIV YELLOW ; IDIV because signed; quotient in AX MOV BLUE, AX

(b) MOV AX, BLACK MUL GREEN ; MUL because unsigned; product in DX—AX SUB AX, WHITE SBB DX, 0 ; pad high word of white with 0’s because unsigned DIV YELLOW ; DIV because unsigned; quotient in AX MOV BLUE, AX (c) MOV AL, BLACK ; one operand of byte multiplication must be in AL MUL GREEN ; MUL because unsigned; product in AX MOV BL, WHITE MOV BH, 0 ; pad high byte of white with 0’s because unsigned SUB AX, BX ; single word subtraction; could also do SUB and SBB on bytes analogously to part (b) DIV YELLOW ; DIV because unsigned; quotient in AL MOV BLUE, AL

  1. (30 pts) In 2008, Sankaran developed a protocol to discover boards called “blades” connected to a circuit. As part of this protocol, each blade writes its 6-byte ID one byte at a time until it receives authorization. Write an 8086 instruction sequence to implement this discovery process as follows. Let ID , slot , and authorize denote byte arrays each containing 6 bytes. Each byte of authorize holds either 0 or 1. Starting from the lowest byte, do the following. Copy the j th byte of ID into the j th byte of slot , then check the j th byte of authorize. If the entry of authorize is 1, then exit and write 1 to byte variable active. If the entry is 0 and you have written all six ID bytes, then exit and write 0 to active. If the entry is 0 and you have not yet written all six ID bytes, then repeat for the next byte. MOV SI, 0 ; pointer into arrays TOP: MOV AL, ID[SI] ; move via register because no memory-to-memory moves MOV SLOT[SI], AL CMP AUTHORIZE[SI], 1 JE AUTH ; if byte of authorize is 1, then move 1 into active INC SI CMP SI, 6 JE N_AUTH ; SI runs from 0 to 5 for six bytes of ID , so have processed six when SI = 6; exit and move 0 into active JMP TOP ; otherwise, continue to next iteration AUTH: MOV ACTIVE, 1 ; when authorized JMP DONE N_AUTH: MOV ACTIVE, 0 ; when none of the six bytes is authorized DONE: