当前位置:文档之家› ECTE333-Example-Paper-2-Solution

ECTE333-Example-Paper-2-Solution

ECTE333-Example-Paper-2-Solution
ECTE333-Example-Paper-2-Solution

University of Wollongong

School of Electrical, Computer and Telecommunications Engineering

ECTE 333: Digital Hardware 2 - Previous Test Paper 2 Solution

Student Name and Number: Mark/20

1) Design a 1-bit ALU slice

which is to be used as part of a 32-bit ALU (with cascaded

1-bit slices as shown in the diagram below). The complete 32-bit ALU must be able to execute the 4 operations below, based on a 2-bit SELECT bus. The signal INC is used as the carry-in to the Least Significant ALU (Bit 0). Full and Half Adders are to be completely drawn using logic gates. [3 marks]

SELECT Operation 00 A 31:0 + B 31:0 + INC 01 NOT A 31:0 10 B 31:0 + INC 11 A 31:0 AND B 31:0

2) The LD instruction is executed on the 32-bit Simple 1-bus RISC datapath studied in

lectures and shown below. Detailed data path components are available in Appendix A. For an example of the 8-bit AVR version of the LD instruction, see Appendix B. The ALU operations available are those operations from Question 1. You may assume the X-pointer register here is also 32-bits and may be placed onto the 32-bit data bus like any other register.

Fill out the table below for each of the four data bus accesses required in the Execute

phase of the instruction. Include also the control signals required for each data transfer to take place, as well as ALU setup codes. Can any data transfers be combined in order to reduce the time taken? [6 marks]

LD r16, X+

* can be combined in one data bus access by triggering both MAin and Cin.

3)The AVR ATmega8515 natively supports 8-bit operations including add, subtract,

multiply, etc. If the programmer requires 16-bit or 32-bit operations, this is not supported natively (automatically by the hardware), however it is possible to write code to do so.

Show how 32-bit addition could be implemented on the ATmega8515 by performing four 8-bit additions and taking into account any carries. An example of the type of addition required is given below:

[2 marks]

r3:r2:r1:r0

+ r7:r6:r5:r4

add r0, r4

adc r1, r5

adc r2, r6

adc r3, r7

4)Design an expanding-opcode Instruction Set Architecture with the following constraints:

?All instructions are 12-bits long

?All immediate value fields are 8-bits long

?All register selection fields are 4-bits long

Show how to allocate:

?12 instructions with 1 register field,

?8 instructions with 1 immediate fields,

?64 instructions with no operands,

?as many instructions with 2 register fields as possible

What is the maximum number of instructions of the last type that can be incorporated?

[3 marks]

The answer is a maximum of SEVEN 2-register instructions can be allocated

5)Write an AVR assembler language code snippet to implement this C programming

language subroutine. You should implement this function passing all parameters on the stack – the input is pushed onto the stack before calling the function and the return value will be expected in the same location after the function has finished.

If any temporary registers are used for calculation within the function, they should be saved – and their values returned before exiting the function. The only exceptions are the X/Y/Z pointers which may be destroyed (used without restoring).

[6 marks]

int function(int a)

{

if (a < 2)

return 1;

else

return ( function(a-1) + function(a-2) );

}

FUNCTION:

push r16 ; save r16 for use as temp reg

push r17 ; save r17 for use as temp reg

in ZH, SPH ; load Stack Pointer into Z

SPL

in ZL,

ldd r16, Z+5 ; load ‘a’ (value at SP+5) into r16

cpi r16, 2 ; compare ‘a’ with 2

brge ELSEPART ; branch to ELSEPART if a >= 2

; this is the trivial case

ldi r16, 1 ; load r16 with the answer 1

std Z+5, r16 ; store answer (1) onto the stack

pop r17 ; restore original r17

pop r16 ; restore original r16

ret ; return from subroutine

ELSEPART:

; this is the recursive case

dec r16 ; r16 = a-1

push r16 ; place r16 on the stack

rcall FUNCTION ; recursive call, answer is on stack

pop r17 ; r17 = function(a-1)

dec r16 ; r16 = a-2

push r16 ; place r16 on the stack

rcall FUNCTION ; recursive call, answer is on stack

pop r16 ; r16 = function(a-2)

add r16, r17 ; r16 = function(a-2)+function(a-1)

in ZH, SPH ; load Stack Pointer into Z again

in ZL, SPL ; (Z pointer was destroyed by calls)

std Z+5, r16 ; store answer onto the stack

pop r17 ; restore original r17

pop r16 ; restore original r16

ret ; return from subroutine

相关主题
文本预览
相关文档 最新文档