Preview

MIPS assembly language

Satisfactory Essays
Open Document
Open Document
610 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
MIPS assembly language
EE 361 Homework 3
Total points = 9
Problem A. [2 pts] What are the MIPS assembly language instructions for the following words (see MIPS reference card at the front of the textbook).
Instruction 1: 100011 00011 00100 00000 00000 000100

Instruction 2: 000000 01101 00010 00110 00000 100000

Instruction 3: 000000 00001 00010 00011 00000 100010

Instruction 4: 000010 00000 00000 00000 00000 001100
This exercise is similar to what a CPU does when it decodes an instruction. It first looks in the opcode field to determine the instruction and its type. Then based on this, it recognizes the rest of the fields of the instruction.
Problem B [2 pt]. Consider the following C language for-loop: for (i = k; i < k+20; i++) j = j + i;

The following is a MIPS assembly language implementation of the for-loop assuming that $3, $4, and $5 are used to store i, j, and k, respectively.

add $3,$0,$5 # i = k;

Loop: addi $1,$5,20 # branch if i >= k+20 slt $1,$3,$1 # $1 = 1 if i < k+20 beq $1,$0,Skip # if $1 == 0 (i.e., i >= 100) then skip for-loop

add $4,$4,$3 # j = j + i; addi $3,$3,1 # i++; beq $0,$0,Loop # go back to beginning of for-loop
Skip:

Write the machine code for the MIPS assembly language instructions. You may use decimal numbers (positive and negative ones) to fill in the fields. Note that all instructions and their machine code versions can be found in front of the green card and in Appendix B.10, especially from pages B-45 to B-73).

Problem C [2 pts]: Implement the following C for loop in MIPS assembly language. Assume that variables x1 and x2 are realized by, respectively, $3 and $4. You may use $1, $2, $5, and $6 for temporary storage. Be sure to put in comments to explain your code.

x1 = 7; while (x1 < x2) { x2 = x2 + x1; x1 = x1 + 15; }
Problem D (3 pts total). The mcc compiler.
The MIPS processor has a

You May Also Find These Documents Helpful

Related Topics