Docsity

EECS 443 Digital Systems Design - Homework 2 Solutions, Assignments of Digital Systems Design

Toggle sidebar
bg1
EECS 443 – Digital Systems Design
Homework 2
Spring 2009
RISC processing is based on the principle that a small
number of highly efficient operations is more effective than
many complex, special purpose instructions. Thus, we need
to start thinking about how typical operations can be imple-
mented using RISC instructions.
Exercise 1Use the instruction set of KURM09 to implement the follow-
ing two operations:
Instruction Meaning
add Rs,Rt,RdRd:=Rs+Rt
sub Rs,Rt,RdRd:=Rs−Rt
or Rs,Rt,RdRd:=Rs∨Rt
and Rs,Rt,RdRd:=Rs∧Rt
set Rs,Rt,msk set status ∧msk
bra msk,off if(msk ∧status)6=0
pc :=pc +off
lw Rs,Rt,off Rt:=M(Rs+off)
sw Rs,Rt,off M(Rs+off):=Rt
jmpl Rs,Rt,o f f Rt:=PC +off
PC0:=Rs
Table 1: KURM instruction set
1. Load R11 with the contents of the memory location stored in R12.
(Register direct)
2. Load R11 with the contents of the memory location stored in the
memory location stored R12. (Register indirect addressing)
3. Copy the contents of the memory location stored in R11 to the
memory location stored in R12. (Memory move)
4. Copy the contents of R10 words of memory starting with the ad-
dress stored in R11 to the memory location starting with R12 .
(Block memory move)
5. Increment R15 by 2. (Standard increment operation)
6. Branch to the address PC +8if the contents of R11 are less than 0.
(BLZ in many instruction sets)
7. Branch to the address PC +8if the contents of R11 are greater
than 1. (BGT in many instruction sets)
8. Simulate a stack push by treating the contents of R12 as data to be
pushed on a stack in memory whose top is pointed to by R15. Your
stack should grown down in memory. (Set up for a function call.)
9. Redo the previous problem as a subroutine. Show an example
call to your subroutine. Assume that the return address for the
subroutine will be stored in R14. (Subroutine definition.)
10. Simulate a stack pop by moving the top element of a stack pointed
to by R15 into R12 .
Exercise 1 is designed to show you the
code that would be generated by a compiler
for some common run-time operations and to
demonstrate that we only need 1addressing
mode per operand for any instruction.
On the stack-based problems, remember to update the stack pointer after
all operations.
pf3

Partial preview of the text

Download EECS 443 Digital Systems Design - Homework 2 Solutions and more Assignments Digital Systems Design in PDF only on Docsity!

Homework 2

Spring 2009

RISC processing is based on the principle that a small number of highly efficient operations is more effective than many complex, special purpose instructions. Thus, we need to start thinking about how typical operations can be imple- mented using RISC instructions.

Exercise 1 Use the instruction set of KURM09 to implement the follow- ing two operations:

Instruction Meaning add Rs ,Rt ,Rd Rd := Rs + Rt sub Rs ,Rt ,Rd Rd := Rs − Rt or Rs ,Rt ,Rd Rd := Rs ∨ Rt and Rs ,Rt ,Rd Rd := Rs ∧ Rt set Rs ,Rt ,msk set status ∧ msk bra msk,off if(msk ∧ status) 6 = 0 pc := pc + off lw Rs ,Rt ,off Rt := M(Rs + off) sw Rs ,Rt ,off M(Rs + off) := Rt jmpl Rs ,Rt ,o f f Rt := PC + off PC′^ := Rs

Table 1 : KURM instruction set

1. Load R 11 with the contents of the memory location stored in R 12. (Register direct)

2. Load R 11 with the contents of the memory location stored in the memory location stored R 12. (Register indirect addressing)

3. Copy the contents of the memory location stored in R 11 to the memory location stored in R 12. (Memory move)

4. Copy the contents of R 10 words of memory starting with the ad- dress stored in R 11 to the memory location starting with R 12. (Block memory move)

5. Increment R 15 by 2. (Standard increment operation)

6. Branch to the address PC + 8 if the contents of R 11 are less than 0. (BLZ in many instruction sets)

7. Branch to the address PC + 8 if the contents of R 11 are greater than 1. (BGT in many instruction sets)

8. Simulate a stack push by treating the contents of R 12 as data to be pushed on a stack in memory whose top is pointed to by R 15. Your stack should grown down in memory. (Set up for a function call.)

9. Redo the previous problem as a subroutine. Show an example call to your subroutine. Assume that the return address for the subroutine will be stored in R 14. (Subroutine definition.)

10. Simulate a stack pop by moving the top element of a stack pointed to by R 15 into R 12. Exercise 1 is designed to show you the code that would be generated by a compiler for some common run-time operations and to demonstrate that we only need 1 addressing mode per operand for any instruction.

On the stack-based problems, remember to update the stack pointer after all operations.

architecture beh of cpu is begin CPU: process M : array of word; R11,R12,R13 : word; PC : word; begin ... end process CPU; end architecture beh;

Figure 1 : VHDL skeleton for a CPU process.

Exercise 2 Assume the VHDL fragment in figure 1 representing the skeleton of a simple CPU model. Using VHDL statements, define behav- iors for the following operators and memory addressing modes: (Note that you need to indicate only the VHDL needed to implement the func- tion. You may assume that word addition and comparison functions ex- ist. These are not necessarily instructions that are defined for KURM09.)

1. lw R 11 #99 - Load R 11 with the value 99.

2. lw R 11 R 12 - Load R 11 from the address stored in R 12

3. lw R 11 (R 12 ) - Load R 11 from the address stored in the memory location at the address in R 12

4. sw R 11 R 13 (R 12 ) - Store R 11 using register indirect addressing with an offset stored in R 13.

5. add R 12 R 13 R 11 - Add contents of R 12 and R 13 storing the result in R 11

6. inc R 11 - Increment R 11 by 1

7. mov R 11 R 12 - Move the contents of R 11 into R 12

8. push R 11 R 12 - Treating the address stored in R 12 as the top of a stack, push the value in R 11 and update R 12 appropriately

9. bze R 11 R 12 - Jump to the instruction with address PC + R 12 only when R 11 contains 0

10. mul R 11 R 12 R 13 - Multiply the contents of R 11 by the contents of R 12 and store the result in R 13 Exercise 2 is designed to get you thinking about assembly instructions as VHDL code. Most of these instructions require only a few lines of VHDL to imple- ment.