$24
[25 pts]
1- In order to make the pseudo-CPU more useful, suppose that we incorporate a single-port register file containing
[25 pts]
2- Now imagine that we take the pseudo-CPU (from problem 1) and add a Stack Pointer (SP). Suppose the pseudo-CPU can be used to implement the AVR instruction ICALL (Indirect Call to Subroutine) with the format shown below:
1001 0101 0000 1001
ICALL pushes the return address onto the stack and jumps to the 16-bit target address contained in the Z register. Give the sequence of microoperations required to Fetch and Execute AVR’s ICALL instruction. Your solution should result in exactly 6 cycles for the fetch cycle and no more than 8 cycles for the execute cycle. Assume the memory is organized into addressable bytes (i.e., each memory word is a byte), MDR is 8 bits, and AC, SP, PC, IR, and MAR are 16 bits. Also, assume the Internal Data Bus is 16-bits wide, and thus can handle 8-bit or 16-bit (as well as portions of 8-bit or 16-bit) transfers in one microoperation and SP has the capability to increment/decrement itself. Clearly state any other assumptions made.
[25 pts]
3- Consider the following AVR assembly code that performs 16-bit by 16-bit multiplication. Hint: See the Lab 5 documentation for relevant background information. Assume the data memory locations $0100 through $0107 initially have the values shown below. Use this information to answer the questions on page 4.
|
.include "m128def.inc" |
; |
Include definition file |
|||
|
.def |
rlo = r0 |
|
; |
Low byte of MUL result |
|
|
.def |
rhi = r1 |
|
; |
High byte of MUL result |
|
|
.def |
A = r2 |
|
|
; |
An operand |
|
.def |
B = r3 |
|
|
; |
Another operand |
|
.def |
zero = r4 |
|
; |
Zero register |
|
|
.def |
oloop = r17 |
|
; |
Outer Loop Counter |
|
|
.def |
iloop = r18 |
|
; Inner Loop Counter |
||
1. |
.org |
$0000 |
rjmp |
INIT |
|
|
|
|
|
|
|||
2. |
INIT: |
|
.org |
$0054 |
; Set zero register to zero |
|
|
clr |
zero |
||||
3. |
MAIN: |
|
ldi |
YL, low(addrB) |
; Load low byte |
|
4. |
|
|
ldi |
YH, high(addrB) |
; Load high byte |
|
5. |
|
|
ldi |
ZL, low(LAddrP) |
; Load low byte |
|
6. |
|
|
ldi |
ZH, high(LAddrP) ; Load high byte |
||
7. |
|
|
ldi |
oloop, 2 |
; Load counter |
|
8. |
MUL16_OLOOP: ldi |
XL, low(addrA) |
; Load low byte |
|||
9. |
|
|
ldi |
XH, high(addrA) |
; Load high byte |
|
10. |
|
ldi |
iloop, 2 |
; Load counter |
||
11. MUL16_ILOOP: ld |
A, X+ |
; Get byte of A operand |
||||
12. |
|
ld |
B, Y |
; Get byte of B operand |
||
13. |
|
mul |
A,B |
; Multiply A and B |
||
14. |
|
ld |
A, Z+ |
; Get a result byte from memory |
||
15. |
|
ld |
B, Z+ |
; Get the next result byte from memory |
||
16. |
|
add |
rlo, A |
; rlo ← rlo + A |
||
17. |
|
adc |
rhi, B |
; rhi ← rhi + B + carry |
||
18. |
|
ld |
A, Z |
; Get a third byte from the result |
||
19. |
|
adc |
A, zero |
; Add carry to A |
||
20. |
|
st |
Z, A |
; Store third byte to memory |
||
21. |
|
st |
-Z, rhi |
; Store second byte to memory |
||
22. |
|
st |
-Z, rlo |
; Store first byte to memory |
||
23. |
|
adiw |
ZH:ZL, 1 |
;Z←Z+1 |
||
24. |
|
dec |
iloop |
; Decrement counter |
||
25. |
|
brne |
MUL16_ILOOP |
; Loop if iLoop != 0 |
||
26. |
|
sbiw |
ZH:ZL, 1 |
;Z←Z-1 |
||
27. |
|
adiw |
YH:YL, 1 |
;Y←Y+1 |
||
28. |
|
dec |
oloop |
; Decrement counter |
||
29. |
|
brne |
MUL16_OLOOP |
; Loop if oLoop != 0 |
||
30. Done: |
$0100 |
rjmp |
Done |
|
|
|
|
.org |
.byte |
2 |
|
|
|
|
addrA: |
|
|
|
||
|
addrB: |
|
.byte |
2 |
|
|
|
LAddrP: |
.byte |
4 |
|
|
[25 pts]
4- Consider the AVR assembly code in Problem #3 with its equivalent (partially completed) address and binaries shown on the right. Determine the values for
Page 5 of 5