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 Computer Architecture and Design Homework 3 Solutions - Prof. Vishwani Agrawal, Assignments of Computer Architecture and Organization

Solutions to problem 1, 2, and 3 of the mips computer architecture and design homework 3, which includes writing assembly code to multiply integers, binary machine code for the program, and checking if the code can be used to implement a mips pseudoinstruction. Additionally, the document provides instructions for saving and restoring registers in a procedure and compiling the code to eliminate the need for register saving and restoring.

Typology: Assignments

Pre 2010

Uploaded on 08/18/2009

koofers-user-pxa
koofers-user-pxa 🇺🇸

10 documents

1 / 2

Toggle sidebar

Related documents


Partial preview of the text

Download MIPS Computer Architecture and Design Homework 3 Solutions - Prof. Vishwani Agrawal and more Assignments Computer Architecture and Organization in PDF only on Docsity! ELEC 5200-001/6200-001 Computer Architecture and Design Spring 2009 Homework 3 Solution Assigned 2/9/09, due 2/20/09 Problem 1: For a MIPS computer that has no hardware multiply instruction implemented, write assembly code to multiply integers a and b, which can have any positive or negative values. Answer: The following program multiplies integers a and b. Here $s0 = a, $s1 = b, and the product is placed in $s3. Note that it leaves the arguments a and b unchanged. add $s3, $zero, $zero # initialize running sum $s3 = 0 beq $s0, $zero, fin # finish if argument a = 0 add $t1, $s1, $zero # copy argument b to $t1 repeat beq $t1, $zero, fin # finish when $t1 is 0 bltz $t1, neg # increase $t1 if b is negative addi $t1, $t1, – 1 # else $t1 is decreased by 1 add $s3, $s3, $s0 # compute running sum of $s0 bgez $t1 repeat neg addi $t1, $t1, 1 # $s1 is increased by 1 sub $s3, $s3, $s0 # compute running sum of $s0 blez $t1 repeat fin add $s3, $t1, $zero # $s3 = a * b Problem 2: Write binary machine code for the program of Problem 1. Answer: The machine code is as follows: 000000 00000 00000 10011 00000 100000 add $s3, $zero, $zero 000100 10000 00000 00000 00000 001001 beq $s0, $zero, fin 000000 10001 00000 01001 00000 100000 add $t1, $s1, $zero 000100 01001 00000 00000 00000 000111 repeat beq $t1, $zero, fin 000001 01001 00000 00000 00000 000011 bltz $t1, neg 001000 01001 01001 11111 11111 111111 addi $t1, $t1, – 1 000000 10011 10000 10011 00000 100000 add $s3, $s3, $s0 000001 01001 00001 11111 11111 111011 bgez $t1 repeat 001000 01001 01001 00000 00000 000001 neg addi $t1, $t1, 1 000000 10011 10000 10011 00000 100010 sub $s3, $s3, $s0 000110 01001 00000 11111 11111 111000 blez $t1 repeat 000000 01001 00000 10011 00000 100000 fin add $s3, $t1, $zero Problem 3: Can the code of Problem 1 be used to implement a MIPS pseudoinstruction? Answer: Yes. Only one extra register, $t1, is used in this code. In pseudocode, This register can be replaced by $at.
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved