MIPS Instruction Set and Computer Architecture, Summaries of Architecture

Information about the MIPS instruction set, including opcode values, instruction formats for types A, B, C, and D, and examples of MIPS instructions and their corresponding pseudoinstructions. It also includes a problem set from a Computer Architecture course at Rose-Hulman Institute of Technology, which covers topics such as variable length instructions, addressing modes, and MIPS assembly language.

Typology: Summaries

2021/2022

Uploaded on 08/05/2022

nguyen_99
nguyen_99 🇻🇳

4.2

(80)

1K documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSSE 232 – Computer Architecture I Rose-Hulman Institute of Technology
Fall 2005-2006 Computer Science and Software Engineering
Profs. Archana Chidanandan and Larry Merkle
1 of 10
Exam 1 - Solutions
Name:____________________________________________________
Instructions:
Write all answers on these pages. Use the back as necessary.
Clearly indicate your final answer.
For full credit, show your work, and document your code.
Read the entire examination before starting, and then budget your time.
Authorized resources:
Green reference card from the text.
Unauthorized resources:
You are NOT permitted to use any resources other than those identified above. In
particular, you may NOT use books, notes, electronic files, calculators, PDAs, or
computers.
Good luck!
Problem
Number
Maximum
Points
Points
Earned
1a 12
1b 12
1c 8
1d 8
2a 12
2b 17
3 16
4 14
Total 99 + 1 bonus
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download MIPS Instruction Set and Computer Architecture and more Summaries Architecture in PDF only on Docsity!

Fall 2005-2006 Computer Science and Software Engineering Profs. Archana Chidanandan and Larry Merkle

Exam 1 - Solutions

Name:____________________________________________________

Instructions:

  • Write all answers on these pages. Use the back as necessary.
  • Clearly indicate your final answer.
  • For full credit, show your work, and document your code.
  • Read the entire examination before starting, and then budget your time.

Authorized resources:

  • Green reference card from the text.

Unauthorized resources: You are NOT permitted to use any resources other than those identified above. In particular, you may NOT use books, notes, electronic files, calculators, PDAs, or computers.

Good luck!

Problem Number

Maximum Points

Points Earned

1a 12

1b 12

1c 8

1d 8

2a 12

2b 17

Total 99 + 1 bonus

Fall 2005-2006 Computer Science and Software Engineering Profs. Archana Chidanandan and Larry Merkle

Problems Problem 1a.[12 points] List the machine language fields and obtain the hexadecimal representation for the following MIPS instructions:

lw $t0, 4($t1) Opcode = 35; rs = $t1 = $9; rt = $t0 = $8; 16-bit signed immediate = 0x

0x8d

addi $s2, $s1, - Opcode = 8; rs = $s1 = $17; rt = $s2 = $18; 16-bit signed immediate = -

0x2232fffb

sub $t3, $t5, $a Opcode = 0; Funct = 34; rs = $t5 = $13; rt = $a0 = $4; rd = $t3 = $

0x01a

Problem 1b. [12 points]Give the MIPS assembly language statements represented by each of the following:

0x27a addiu $5, $29, 4 or addiu $a1, $sp,

0x001a srl $4, $26, 2 or srl $a0, $k0, 2

0x116a beq $11, $10, 4 or beq $t3, $t2, loop

Fall 2005-2006 Computer Science and Software Engineering Profs. Archana Chidanandan and Larry Merkle

Problem 2. You are designing an architecture with variable length instructions. Some instructions are 12 bits long, while others are 24 bits long. There are 8 general purpose registers and each of these registers is 12 bits wide. Addresses and immediates are also 12-bits wide. The instructions and their types are listed in the table below.

Instruction Type Action Length 1 Add rd, rs A Reg[rd] = Reg[rs] + Reg[rd] 12 bits 2 Sub rd, rs A Reg[rd] = Reg[rs] – Reg[rd] 12 bits 3 Jr rs A PC = Reg[rs] 12 bits 4 And rd, rs A Reg[rd] = Reg[rd] and Reg[rs]

12 bits

5 Or rd, rs A Reg[rd] = Reg[rs] or Reg[rd] 12 bits 6 Getinput rd, rs A Reg[rd] = SpecialRegister[rs]

12 bits

  1. Putoutput rd, rs A SpecialRegister[rd] = Reg[rs]

12 bits

8 Addi, rd, rs, 12-bit immediate

B Reg[rd] = Reg[rs] + 12-bit immediate

24 bits

9 Beq rd, rs, 12-bit address B If (Reg[rs] = = reg[rd]) PC = 12-bit address

24 bits

10 Bne rd, rs, 12-bit address B If (Reg[rs] != Reg[rd]) PC = 12-bit address

24 bits

11 Lw rd, 12-bit address (rs) B Reg[rd] = Mem[Reg[rs] + 12-bit address]

24 bits

12 Sw rd, 12-bit address (rs) B Mem[Reg[rs] + 12-bit address] = Reg[rd]

24 bits

13 Sl rd, rs, 5-bit immediate B If(5-bit immediate > 0) Reg[rd] = Reg[rs] << 5-bit immediate else Reg[rd] = Reg[rs] >> 5-bit immediate

24 bits

14 J 9-bit address C PC = PC[11:9] || 9-bit address

12 bits

15 Jal 9-bit address C PC = PC[11:9] || 9-bit address Reg[7] = PC

12 bits

16 Rfe C PC = EPC 12 bits 17 Slt rd, rs, rt D If(Reg[rs] < Reg[rt]) Reg[rd] = 1; Else Reg[rd] = 0

12-bits

Fall 2005-2006 Computer Science and Software Engineering Profs. Archana Chidanandan and Larry Merkle

a. [12 points] Show the instruction format for each type i.e. A, B, C, and D. Indicate clearly how many bits are allocated for each field. Hint: Start with the C and D types. One possible solution: A type format 11 9 8 6 5 3 2 0 Opcode rd rs Function field

B type format

C type format

D type format 11 9 8 6 5 3 2 0 Opcode rd rs rt

b. [17 points] For each of the instructions below, assign a value for the opcode field, as well as values for any fields that augment the opcode (e.g. the funct field for MIPS R-type instructions)

One possible assignment Instruction Opcode Values of fields that augment opcode Add 000 000 Sub 000 001 Jr 000 010 And 000 011 Or 000 100 Getinput 000 101 Putoutput 000 110 Addi 001 000 Beq 001 001 Bne 001 010 Lw 001 011 Sw 001 100 Sl 001 101 J 010 No field Jal 011 No field Rfe 100 No field Slt 101 No field

16-bit immediate Opcode rd rs Function field

Opcode 9-bit immediate

Fall 2005-2006 Computer Science and Software Engineering Profs. Archana Chidanandan and Larry Merkle Problem 4 [14 pts] Complete the MIPS program on the following pages by filling in the provided spaces with MIPS assembly language statements such that:

  • The procedure dotProduct accepts three input parameters: the addresses of two arrays and the size of the arrays.
  • The procedure dotProduct returns the dot product of the vectors represented by the two arrays.
  • The procedure dotProduct follows MIPS register usage conventions.
  • The main program calls the procedure dotProduct in such a way that the dot product (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) · (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) = 0 + 2 + 6 + 12 + … + 90 = 330 is displayed.

Assume the existence of another MIPS procedure product that returns in $v the product of its two integer parameters, which are passed in $a0 and $a1. In other words, even though product is not shown, you may call it, and you do not need to write it.

Read all the provided parts of the program, before you begin.

Fall 2005-2006 Computer Science and Software Engineering Profs. Archana Chidanandan and Larry Merkle

Procedure dotProduct calculates and returns x (dot) y,

where the address of x, the address of y, and their

(common) size are the three parameters of the procedure.

A high-level language description of the procedure follows:

/**

* @param x First array

* @param y Second array

* @param size Number of elements in each array

* @return sum The dot product

*/

private static int dotProduct(

int[] x, int[] y, int size ) {

int sum = 0;

for( int count = 0; count < size; count++) {

sum = sum + product( x[ count ] , y[ count ] );

}

return sum;

}

“Public” register usage:

$a0 - address of x

$a1 - address of y

$a2 - number of elements in each array

$v0 – x (dot) y

“Private” register usage:

$s0 – address of x[ count ]

$s1 – address of y[ count ]

$s2 - size

$s3 – count

$s4 – sum

$t0 - flag

Procedure entrance and initialization

dotProduct: addi $sp, $sp, -16 # Create space on the stack sw $ra, 0($sp) # Place values to be preserved sw $s0, 4($sp) # on the stack. sw $s1, 8($sp) sw $s2, 12($sp)

Read input arguments from the

argument registers

move $s0, $a0 # $s0 = address of x[ count ] move $s1, $a1 # $s1 = address of y[ count ] move $s2, $a2 # $s2 = size move $s3, $0 # count = 0 move $s4, $0 # sum = 0

loop: slt $t0, $s3, $s2 # if( count < size) beq $t0, $0, exit1 # continue lw $t1, 0($s0) # Read x[ count ] from memory lw $t2, 0($s1) # Read y[ count ] from memory

Call “product” and pass

parameters

Fall 2005-2006 Computer Science and Software Engineering Profs. Archana Chidanandan and Larry Merkle

Sample data starts here

.data x: .word 0 1 2 3 4 5 6 7 8 9 y: .word 1 2 3 4 5 6 7 8 9 10 N: .word 10 Msg: .asciiz "The dot product is”