Docsity

8086 Assembly Solutions for EE 3750 Test 1 - Prof. J. Trahan, Exams of Electrical and Electronics Engineering

Toggle sidebar
bg1
EE 3750 — Test 1 solutions 1
EE 3750 — Test 1 solutions
Fall 2008
1. (20 pts) Consider each of the instructions below, executed separately (not in
sequence), with initial register values (in hexadecimal) as follows: AX = 4234, BX = 0A0A, CX
= 4FFF, DX = 4947. For each instruction, identify the result of the instruction that is stored in
AH and specify the resulting SF, PF, and ZF flags.
AND AH, DL
ADD AH, DL
AND: AH ← 42H (= 0100 0010 B); SF = 0, PF = 1, ZF = 0
ADD: AH ← 89H (= 1000 1001 B); SF = 1, PF = 0, ZF = 0
2. (20 pts) For the sequence of instructions below, let the offset of green be 620 and the
offset of brown be 8C6, and let the registers have the following initial contents: DS = 2000, ES
= 3500, SI = 227, DI = 4D6, CX = 22, where all values are in hexadecimal.
(a) Specify the contents of all registers changed by the instruction REP MOVSW.
(b) Explain what this sequence of instructions accomplishes.
(c) Write an 8086 assembly language instruction sequence to accomplish the same result,
but without using any string transfer instructions.
CLD
PUSH DS
POP ES
MOV SI, OFFSET GREEN
LEA DI, BROWN
MOV CX, 4
REP MOVSW
(a) SI = 628H (620 + 8)
DI = 8CE (8C6 + 8)
CX = 0
(b) REP MOVSW copies four words from array green to array brown.
(c)
MOV CX, 4 ; to copy 4 times
MOV BX, 0
TOP; MOV AX, GREEN[BX]
MOV BROWN[BX], AX ; copies word from green to brown
ADD BX, 2 ; update pointer
LOOP TOP
pf2

Partial preview of the text

Download 8086 Assembly Solutions for EE 3750 Test 1 - Prof. J. Trahan and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

EE 3750 — Test 1 solutions 1

EE 3750 — Test 1 solutions

Fall 2008

  1. (20 pts) Consider each of the instructions below, executed separately (not in sequence), with initial register values (in hexadecimal) as follows: AX = 4234, BX = 0A0A, CX = 4FFF, DX = 4947. For each instruction, identify the result of the instruction that is stored in AH and specify the resulting SF, PF, and ZF flags. AND AH, DL ADD AH, DL AND: AH ← 42H (= 0100 0010 B); SF = 0, PF = 1, ZF = 0 ADD: AH ← 89H (= 1000 1001 B); SF = 1, PF = 0, ZF = 0
  2. (20 pts) For the sequence of instructions below, let the offset of green be 620 and the offset of brown be 8C6, and let the registers have the following initial contents: DS = 2000, ES = 3500, SI = 227, DI = 4D6, CX = 22, where all values are in hexadecimal. (a) Specify the contents of all registers changed by the instruction REP MOVSW. (b) Explain what this sequence of instructions accomplishes. (c) Write an 8086 assembly language instruction sequence to accomplish the same result, but without using any string transfer instructions. CLD PUSH DS POP ES MOV SI, OFFSET GREEN LEA DI, BROWN MOV CX, 4 REP MOVSW (a) SI = 628H (620 + 8) DI = 8CE (8C6 + 8) CX = 0 (b) REP MOVSW copies four words from array green to array brown. (c) MOV CX, 4 ; to copy 4 times MOV BX, 0 TOP; MOV AX, GREEN[BX] MOV BROWN[BX], AX ; copies word from green to brown ADD BX, 2 ; update pointer LOOP TOP

EE 3750 — Test 1 solutions 2

  1. (30 pts) Write an 8086 assembly language instruction sequence to do the following, which is part of a calculation of chip utilization for a set of tasks running on an FPGA. Calculate the sum over all accepted tasks of the product of area and time for each task. Let size denote the number of tasks (where size > 0). Let accept denote a byte array in which the i th entry is 1 if the i th task is accepted and 0 otherwise; let area ( time , respectively) denote a byte array in which the i th entry holds the area (execution time, respectively) of the i th task. Each array has size entries. Store the result in word variable sum. MOV CX, SIZE ; loop counter MOV DI, 0 ; initialize pointer into arrays MOV BX, 0 ; initialize accumulator CHECK: CMP ACCEPT[DI], 1 JNE NEXT ; if not 1, then proceed to next task MOV AL, AREA[DI] ; if accepted, then calculate area-time product MUL TIME[DI] ADD BX, AX ; add to accumulator NEXT: INC DI LOOP CHECK MOV SUM, BX ; store result
  2. (30 pts) Write an 8086 assembly language instruction sequence to do the following. Implement the actions of 16 JK flip-flops in parallel. See the circuit below for one JK flip-flop built from a D flip-flop. Word variables Jword , Kword , and Qword hold the inputs. Your code is to calculate as output the updated value of Qword , where Qword holds the outputs of 16 D flip-flops, and Jword and Kword each hold the inputs to these 16 D flip-flops. MOV AX, QWORD MOV BX, AX ; copy of Qword AND BX, JWORD ; top AND gate NOT AX ; complement Qword MOV CX, KWORD NOT CX AND AX, CX ; bottom AND gate OR AX, BX ; OR gate with input to D MOV QWORD, AX