Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

MIPS Assembly Exercises: Hexadecimal to Binary Conversion and Instruction Encoding, Slides of Advanced Computer Architecture

A series of exercises related to MIPS assembly programming. The exercises involve converting hexadecimal numbers to binary, encoding MIPS instructions, and writing MIPS assembly code for given conditions. These exercises are intended for students studying MIPS assembly language and computer architecture.

What you will learn

  • What is the MIPS instruction represented by the binary entry 1000 1101 0000 1001 0000 0000 0100 0000?
  • What binary number represents the hexadecimal number 7fff fffa?
  • What is the MIPS assembly code for the given condition: if (g != j) h = g - h; else h = g + h;?

Typology: Slides

2021/2022

Uploaded on 08/05/2022

nguyen_99
nguyen_99 🇻🇳

4.2

(80)

1K documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
(6 pts) Exercise 2-8
(See number discussion in Section 2.5)
What binary number does this hexadecimal number represent:
7fff fffahex?
What decimal number does it represent?
(10 pts) Exercise 2-9
Show the hexadecimal representation of this MIPS instruction:
add $t0 , $t1 , $zero
pf3
pf4
pf5
pf8

Partial preview of the text

Download MIPS Assembly Exercises: Hexadecimal to Binary Conversion and Instruction Encoding and more Slides Advanced Computer Architecture in PDF only on Docsity!

(See number discussion in Section 2.5)

  • What binary number does this hexadecimal number represent: 7fff fffahex?
  • What decimal number does it represent?

(10 pts) Exercise 2-

Show the hexadecimal representation of this MIPS instruction:

add $t0 , $t1 , $zero

What MIPS instruction is represented by this binary entry:

1000 1101 0000 1001 0000 0000 0100 0000

(5 pts) Exercise 2-

  • What is the MIPS assembly code for the following: if (g != j) h = g - h; else h = g + h; Variables f to j are assigned to registers $s0 to $s

i $s

j $s

h $s i $s j $s

  • What is the MIPS assembly code for the following: if ( ( (g != h) && (f == i) ) || (g == i) ) g = i + j; Variables f to j are assigned to registers $s0 to $s

f $s g $s h $s i $s j $s

(blank)

(20 pts) Exercise 2-18: Pseudo-instructions

f $s

f $s

g $s h $s i $s j $s

  • Below you will see several problems of the form: li $t1, small # $t1 = small
  • This is an example pseudo-instruction, with its meaning given as a comment. The instruction should load ‘small’ into $t1, where ‘small’ means a constant that fits within 16 bits. The constant is also called an ‘immediate’ – ‘li’ stands for ‘load immediate’
  • Your job is to write the real MIPS instruction (or sequence of instructions) that the compiler would produce for each given pseudo-instruction. For instance, the solution for the above pseudo-instruction is: addi $t1, $zero, small
  • A ‘big’ constant needs 32 bits to be represented. You will need some notation to talk about the upper (most significant) 16 bits and the lower (least significant bits of this number. Use UPPER(big) to refer to the most significant bits and LOWER(big) to refer to the other bits.
  • To make your answers simpler, you may make use of the ‘li’ psuedo- instruction where helpful (except when defining li itself). Do this – it will make your job easier!!
  • clear $to # $t0 = 0
  • beq $t1, small, L # if ($t1 == small) go to L
  • beq $t2, big, L # if ($t2 == big) go to L
  • li $t2, big # $t2 = big
  • bge $t5, $t3, L # if ($t5 >= $t3) go to L
  • lw $t5, big($t2) # t5 = Memory[$t2+big]
  • a.) What is the MIPS assembly code for the following: while (g < i) { g = g + j; } Variables f to j are assigned to registers $s0 to $s Use $v0, $v1 as temporaries if needed b.) Did your solution use any pseudo-instructions?

f $s g $s

h $s

h $s

i $s j $s

(10 pts) Exercise 2-

  • a.) What is the MIPS assembly code for the following: while (g > i) { g = g + 3; } Variables f to j are assigned to registers $s0 to $s Use $v0, $v1 as temporaries if needed b.) Did your solution use any pseudo-instructions?

f $s g $s h $s i $s j $s

  • The MIPS translation of the C segment: while (save[i] == k) i = i + 1; is given on page 107-108 as follows: Loop: sll $t1, $s3, 2 # temp reg t1 = i * add $t1, $t1, $s6 # t1 = address of save[i] lw $t0, 0($t1) # temp reg t0 = save[i] bne $t0, $s5, Exit # goto Exit if save[i] != k add $s3, $s3, 1 # loop body: i = i + 1 j Loop # repeat the loop
  • This code uses both a conditional branch and an unconditional jump each time through the loop. Only poor compilers would produce code with this loop overhead. Rewrite the assembly code so that it uses at most one branch or jump each time through the loop.