elec1601代写-ELEC9601
时间:2022-11-03
ELEC1601_ELEC9601 End of Sem (practice) 
Started: Nov 3 at 23:57 
Quiz Instructions 
1 ptsQuestion 1 
A machine code must support arithmetic instructions of the following format: 
opcode, destination register, source register. 
e.g. XOR, R1, R2 translates to perform the bitwise xor of R1 and R2 and stores 
the result in R1 

The total number of different arithmetic instructions that must be supported is 197, 
with 2^6 different registers. All bits for this instruction are utilised in the encoding. 
What is the minimum number of bits required for this machine code? 


1 ptsQuestion 2 
Suppose you have a circuit that implements the following truth table:  
x y z Out 
0 0 0 0 
0 0 1 0 
0 1 0 1 
0 1 1 1 
1 0 0 1 
1 0 1 1 
1 1 0 1 
1 1 1 0 
Suppose you then create two instances of this circuit and wire them up as follows 
(the second instance has its middle input inverted): 
What is the output of the circuit if a=0, b=0, c=1? 
1 ptsQuestion 3 
Study the following circuit and timing diagram (consisting of D-type latches, D-type 
Flip-Flops and Logic Gates): 
What is the value for Out at the highlighted times (if it cannot be determined, write 
UNKNOWN) 
(highlighted red) = [ Select ] 
(highlighted yellow) = [ Select ] 
1 ptsQuestion 4 
Study the following Finite State Machine: 
Complete the truth table showing how to compute the next state from the current 
state, you should assume the following binary encoding: 
State A: 00  
State B: 01 
State C: 10 
State D: 11 
Where state(1) (and nextState(1)) is the MSB 
State(1) State(0) I nextState(1) nextState(0) 
0 0 0 
0 0 1 
0 1 0 
0 1 1 
1 0 0 
1 0 1 
1 1 0 
1 1 1 

1 ptsQuestion 5 
Assume that a memory is initialised as follows: 
Memory 
Address 
Cell 
Contents 
0xC336 0x11 
0xC337 0x11 
0xC338 0x00 
0xC339 0x10 
0xC33A 0x01 
0xC33B 0x01 

Suppose the X register is initialised to 0xC338 and the following commands are 
issued: 
LD R1, X+ 
LD R2, X+ 
ADD R1, R2 
ST X, R1  
What is the value in 0xC338? (Write your answer in decimal) 
1 ptsQuestion 6 
Assume that a memory is initialised as follows: 
Memory 
Address 
Cell 
Contents 
0x00C336 0x83 
0x00C337 0x48 
0x00C338 0x64 
0x00C339 0x43 
0x00C33A 0x10 
0x00C33B 0x08 

A computer system has the value 0x00C338 in its stack pointer. The stack grows 
(when you push data) towards lower memory positions. Suppose the system 
executes the sequence of instructions: 
POP R1 
POP R2 
ADD R1 R2 
MOV R2 R1 
ADD R2 R2 
PUSH R1 
PUSH R2 
PUSH R3 
What value is in R3. (Write your answer in decimal. If it cannot be computed given 
the above information, enter the value 0) 
1 ptsQuestion 7 
Suppose the following two instructions are executed:  
ANDI R20, 5 
BREQ Destination 
The machine code for the BREQ instruction is as follows: 
1111 0000 0001 1001 

Assume the following register values:  
Program counter = 0x001 
R20 = 0x07 
What is the new value of the PC? 

The relevant information for the instruction set is given below: 
1 ptsQuestion 8 
Study the following code (you can assume ". . ." refers to code that is not shown) 
main:  
...  
LDI R27, hi8(d1) ; PC = 0x0A34, SP = 0x0B18  
LDI R26, lo8(d1)  
LD R18, X+  
PUSH R0  
CALL subroutine1  
POP R18 ; What is the value of the PC after the completion of this line 
of code?  
...  

subroutine1:  
POP R18  
...  
RET 

You can assume that the address of subroutine1 is 0x1A14 and that this code 
was generated by the AVR-GCC compiler and follows the relevant conventions 
What is the value of the Program Counter after the completion of the highlighted 
line of code? (Write your answer in Decimal) 
1 ptsQuestion 9 
Consider the following definitions for d1, which represents a 4 byte array of integer 
values: 
d1: .byte 0, 1, 2, 3 
(1st element of the array for d1 has the value 0, 4th element of the array has the 
value 3) 

If d1 is located in address 0x0534, what is the value of the second element of d1 
after executing the following instructions? (Write your answer in Decimal) 
LDI R27, hi8(d1) 
LDI R26, lo8(d1) 
LDI R19, hi8(d1) 
LDI R18, lo8(d1) 
ST X+, R18 
ST X+, R19 
1 ptsQuestion 10 
An AVR assembly program defines the following variables and labels: 
.section .data 
D1: .byte 9, 4, 9, 6 
D2: .byte 3, 6 
If the address of D1 is 0x67, what is the address of D2? (Write your answer in 
Decimal) 
1 ptsQuestion 11 
What is the decimal value (base 10) held in R9 after the following sequence of 
instructions? 

LDI R18, 0x36 
MOV R9, R18 
SUB R18, R9 
1 ptsQuestion 12 
Study the following program 
It was generated by the compiler avr-gcc that uses the AVR libc library, so obeys 
the convention for register management 

LDI R18, 7  
PUSH R18  
PUSH R20  
CALL subroutine1; Call the subroutine  
POP R2  
POP R3  
ADD R20 R2  
ADD R20 R3  
ADD R20 R18  
... 
subroutine1:  
...  
ADD R18 R20; Values for the registers after completion of this line of code a 
re shown in the text below  
PUSH R0;  
RET; 
Suppose at the start of the subroutine, R18 = 2, R20 = 5; 
Suppose at the end of the subroutine after completion of the line highlighted in 
Red: R0=9, R2=6, R18=4 
What is the value stored in R20 at the line highlighted in Green? Write 0 if 
unknown. Write your answer in Decimal 
1 ptsQuestion 13 
Study the following program 
It was generated by the compiler avr-gcc that uses the AVR libc library, so obeys 
the convention for register management 
LDI R20, 5  
LDI R21, 3  
LDI R22, 8  
LDI R23, 6  
LDI R24, [a5]  
PUSH R20  
PUSH R21  
PUSH R22  
PUSH R23  
PUSH R24  
CALL subroutine1; Call the subroutine  
... 
subroutine1:  
IN R31, 0x3E ; Z <- SP  
IN R30, 0x3D  
LDD R18, Z+4  
LDD R19, Z+5  
ADD R18, R19 ; What is the value for R18 after execution of this line?  
...  
Reminder, the IN R31, 0x3E ; IN R30, 0x3D commands load the stack pointer into 
the Z register 
What is the value stored in R18 in subroutine 1 (before the ...). Write 0 if unknown. 
Write your answer in Decimal 
1 ptsQuestion 14 
Study the following handwritten (potentially buggy) code (you can assume ". . ." 
refers to code that is not shown 
main:  
...  
LDS R25, x  
PUSH R25,  
CALL subroutine1 ; This instruction is at location 0x1285  
POP R0,  
...  
subroutine1: ; This subroutine is at location 0xAB23  
MOV R25, R8  
PUSH R0  
CALL subroutine2  
POP R25  
...  
MOV R24, R7 ; result  
RET  
subroutine2: ; This subroutine is at location 0xAD75  
Not saved  
POP R0  
POP R0  
POP R0  
RET 
Assume the return address stored in the stack by the CALL instruction is 3 bytes. 
What is the value of the Program Counter after the RET instruction in Subroutine 
1? (Write your answer in Decimal, write 0 if unknown) 
1 ptsQuestion 15 
Suppose you have a computer system with a 4 stage pipeline and clock period of 
213 ns. 
Assuming there are no pipeline stalls (no branching, no I/O requests, no interrupts 
etc.) and a program is run for 4 s, how many instructions could be completed? 

Submit Quiz 
essay、essay代写