Quiz 3
| Type | Assessment |
|---|

Answer
The LD/ST instruction are incorrect and do not assemble
A is at x4000, B is at x4001. It is too large of an offset to fit into LD's 9 2's complement bit
- What is true about the FETCH macrostate?
- Writes to memory, asserting both MEM.EN and MEM.WE Control Signals
- Requires 3 clock cycles
- Determines whether or not a branching instruction will occur based off of thee current conditional code registers
- Place the instruction to be executed into the IR
- Increments the PC by 1 to prepare for the next instruction
Answer
b, d, e
- Caller/Callee Responsibilities
- Pushing arguments for the subroutine onto the stack is the responsibility of the ?
- Restoring the general-purposed registers with the saved values is the responsibility of the ?
- Restoring the old frame pointer and return address is the responsibility of the ?
- Deallocating the space for thee return value is the responsibility of the ?
Answer
- Caller
- Callee
- Callee
- Caller
8.
Vers. A
- Please convert the following hexadecimal value to assembly instruction it corresponds to: 0x1801
- Convert the instruction marked by ???? on line 2 to its corresponding hex value
.ORIG x3000
LEA R3, A ;????
ADD R3, R3, #1
HALT
.END
.ORIG x3010
A .FILL x4000
.ENDAnswer
- 1801 = 0001 100 000 0 00 001
0001 = ADD
DR = R4
SR1 = R0
SR2 = R1
x1801 = ADD R4, R0, R1
- LEA = 1110
R3 = 011
PCOffset = Address of A - Address of LEA execution = 3010 - 3001 = 0xF = 0b0001111
1110 011 0001111 = E60F
- 1801 = 0001 100 000 0 00 001
Vers. B
.ORIG x3000
LEA R0, ARRAY
LDR R1, R0, #5
ADD R1, R1, #4
ST R1, ARRAY ;????
HALT
.END
.ORIG x3020
ARRAY
.fill 7
.fill 2
.fill 9
.fill 10
.fill 4
.fill 11
.ENDAnswer
ST = 0011
SR = R1 = 001
PCOffset9 = ARRAY
At line 4, PC = x3004. PCOffset9 x3020 - 0x3004 = 0x1C = 0b000011100
0011 001 000011100 = 0x321C
- The following program should iterate over an array, find the largest value, and store it at the label RES.FILL in the 3 missing instructions denoted by 'BLANK X' to make this code functional.
.orig x3000 LD R0, SIZE LD R1, ARRAY LDR R3, R1, #0 ;;R3 = R1 = ARRAY, Value of ARR[0] BLOCK ADD R0, R0, #-1 ;;R0 = size - 1, index number BRn SKIP ;;If R0 < 0, SKIP LDR R2, R1, #0 ;;R2 = R1 = value of ARRAY[I] ; BLANK 1 ;;NOT R4, R2; ADD R4, R4, #1 ;;R4 = R4 + 1 ADD R4, R3, R4 ;;R4 = R3 + R4 (R4 + 1 + R3) ; BLANK 2 ;;BRzp KEEP ADD R3, R2, #0 ;;R3 = R2 + 0, R3 holds the max val KEEP ADD R1, R1, #1 ;;R1 = R1 + 1 BRnzp BLOCK ;;loop SKIP ; BLANK 3 ;;ST R3 RES HALT ARRAY .fill x4000 SIZE .fill 5 RES .blkw 1 .end .orig x4000 .fill -1 .fill 10 .fill 6 .fill -2 .fill 6 .end i = arr.length - 1 if (i >= 0) { R4 = ~arr[i] //NOT R4, R2 R4 = R4 + 1;//2's complement R4 = -arr[i] R4 = R3 + R4; //BR ADD R3, R2 + 0; --> if (R4 > R3) R4 - R3 >= 0 }What is Blank 1, Blank 2 and Blank 3
Answers
Blank 1: NOT R4, R2
Blank 2: BRzp KEEP
Blank 3: ST R3, RES
- The developers of the LC-3 have decided that they want to add a new instruction to the existing instruction set: JMPA for "jump to registers added". The instruction format is as follows:
JMPA SR1, SR2
JMPA is meant to use the sum of two registers as an address, look up the value at that address in memory, and use that value retrieved from memory as an address which the program's execution will jump to. This new instruction will take three clock cycles to execute.
For each clock cycle, drag the proper signals that will need to be used in order to execute the JMPA instruction as described. Each clock cycle should contain all of the relevant signals, and not contain any unnecessary signals. You do not need to use all of the available options.
MEM.WE
MEM.EN
LD.MDR
ALUK = PASSA
ALUK = ADD
SR2MUX = REGFILE
LD.MAR
GateMDR
GateALU
SR2MUX = SEXT
PCMUX = ADDER
LD.PC
MARMUX = ADDER
PCMUX = BUS
GateMARMUX
Answer
1st Clock Cycle
ALUK = ADD
LD.MAR
GateALU
SR2MUX = REGFILE
2nd Clock Cycle
MEM.EN
LD.MDR
3rd Clock Cycle
GateMDR
PCMUX = BUS
LD.PC
- In this question, you have to write a program with 5 instructions maximum. You cannot use pseudo-ops or TRAPs. The template code is shown in the image below. You can only use R4-R7 as temporary registers. Do NOT touch R0-R3. If you go over 5 instructions, use pseudo-ops, TRAPs, or modify R0-R3, you will be given 0 points for this problem.
Copy the value at array[3] to array[0].
.ORIG x3000 ;;YOUR CODE HERE HALT .END .ORIG x3020 ARRAY .fill 7 .fill 2 .fill 9 .fill 10 .fill 4 .fill 11 .ENDAnswer(not correct?)
LEA R4, ARRAY ;;Load array ADD R5, R4, #3 ;;get address arr[3] LDR R5, R5, #0 ;;get value arr[3] ADD R6, R4, #0 ;;get address arr[0] STR R5, R6, #0 ;;set R6 to R5
- In this question, you have to write a program with 5 instructions maximum. The template code is shown in the image below. You cannot use any extra psuedo-ops, TRAPs. Also, you can use registers R0-R2, but not any other ones.
Multiply the value in R2 by 6 and store it back in R2.
.ORIG x3000R2 ;;YOUR CODE HERE HALT .ENDAnswer(debugged on complex, should be right)
ADD R2, R2, R2 ;;R2 = 2R2 AND R0, R0, 0 ADD R0, R2, #0 ;;R0 = 2R2 ADD R2, R2, R2 ;;R2 = 2R2 + 2R2 = 4R2 ADD R2, R2, R0 ;; R0 = 4R2 + 2R2 = 6R2
- Write a program to iterate over a null-terminated string, incrementing every numeric character by one while ignoring all other characters. Incrementing the character '9' should result in it overflowing to '0'. You may assume that the string is non-empty and contains strictly alphanumeric characters.
For example, the string "0123456789Test" would become "1234567890Test"
Rules:
- Do not use more than 25 instructions
- You can use all 8 registers R0 through R7
- This can be done in ~15 lines
- You cannot use pseudo-ops or traps
Pseudocode:
int i = 0; while (str[i] != '\0') { if (str[i] == '9') { str[i] = '0'; } else if (str[i] < '9') { str[i] = str[i] + 1; } i++; }A skeleton program is provided below:
.ORIG X3000 ;;YOUR CODE HERE HALT ZERO .fill #48 ;; the ASCII value of '0' NINE .fill #57 ;; the ASCII value of '9' STRING .fill x6000 ;;thee start address of the input string .end .orig x6000 .stringz '0123456789Test' .endAnswer(debugged on complex, should be right idk)
.orig x3000 AND R0, R0, #0 ;;R0 = i = 0 LD R1, STRING ;;address of STRING WHILE AND R2, R2, 0 ADD R2, R2, R1 ;;R2 = address of STRING[i] LDR R3, R2, #0 ;;R3 = value of STRING[i] BRz TERMINATE ;;end loop if string[i] == '\0' NOT R4, R3 ADD R4, R4, #1 ;;R4 = -STRING[i] LD R5, NINE ;;Load ASCII value 9 to R5 ADD R5, R5, R4 ;;R5 = 9 - STRING[i] BRz IF ;;9 == STRING[i] ADD R5, R5, #0 BRp ELSE ;;9 > STRING[i] IF LD R5, ZERO STR R5, R2, #0 ;;store value of R5(zero) to address of STRING[i] ELSE ADD R6, R3, #1 ;;R6 = STRING[i] + 1 STR R6, R2, #0 ;;Store R6 at STRING[i] ADD R0, R0, #1 ;;i = i + 1 BR WHILE ;;Loop TERMINATE HALT ZERO .fill #48 ;; the ASCII value of '0' NINE .fill #57 ;; the ASCII value of '9' STRING .fill x6000 ;;the start address of the input string .end .orig x6000 .stringz "0123456789Test" .end
