Programming Assignment 2 - Introduction to Computer Organization | CDA 3101, Study Guides, Projects, Research of Computer Architecture and Organization

Material Type: Project; Class: INTRO TO COMPU ORGNZN; Subject: COMPUTER DESIGN/ARCHITECTURE; University: University of Florida; Term: Unknown 1989;

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 03/18/2009

koofers-user-zoy
koofers-user-zoy 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CDA3101Fall08ProgrammingAssignment2
Dateassigned:September23,2008
Duedate:October7,2008(11:59pm)
PrimaryTA:ZhuoHUANG([email protected])
1. Overview
ThepurposeofthisassignmentistoimplementtheBinarySearchusingtheMIPSassembly
language,andtosimulateyourprograminSPIM(theMIPSsimulator).Youshouldcomment
yourcodeaswellassimulateitasdescribedinthesimulationsection.Youwillberequiredto
submityourcommentcodeandtheresultsofyoursimulationbytheduedateabove.
2. BinarySearch
Afastwaytosearchasortedarrayistouseabinarysearch.Theideaistolookattheelementin
themiddle.Ifthekeyisequaltothat,thesearchisfinished.Ifthekeyislessthanthemiddle
element,doabinarysearchonthefirsthalf.Ifit'sgreater,doabinarysearchofthesecondhalf.
Thebinarysearchproceduremustreturnthepositioniffound,and‐ 1ifnotfound.
ThesamplecodeofBinarysearchisasfollows:
BinarySearch(A[0..N-1], key, low, high) {
if (high < low)
return -1 // not found
mid = (low + high) / 2
if (A[mid] > key)
return BinarySearch(A, key, low, mid-1)
else if (A[mid] < key)
return BinarySearch(A, key, mid+1, high)
else
return mid // found
}
3. Requirements
3.1.Yourcodemusthaveonemainprocedureandonebinarysearchprocedure.It
canhavemoreproceduresifneeded.
3.2.Thecodecontainsonearraythatholds16sortedintegersandoneinteger
named“key”asinput.Theoutputshouldbestoredinanotherintegernamed“position”.
pf3

Partial preview of the text

Download Programming Assignment 2 - Introduction to Computer Organization | CDA 3101 and more Study Guides, Projects, Research Computer Architecture and Organization in PDF only on Docsity!

CDA 3101 Fall 08 Programming Assignment 2

Date assigned: September 23, 2008

Due date: October 7, 2008 (11:59 pm)

Primary TA: Zhuo HUANG ([email protected])

1. Overview

The purpose of this assignment is to implement the Binary Search using the MIPS assembly language, and to simulate your program in SPIM (the MIPS simulator). You should comment your code as well as simulate it as described in the simulation section. You will be required to submit your comment code and the results of your simulation by the due date above.

2. Binary Search A fast way to search a sorted array is to use a binary search. The idea is to look at the element in the middle. If the key is equal to that, the search is finished. If the key is less than the middle element, do a binary search on the first half. If it's greater, do a binary search of the second half.

The binary search procedure must return the position if found, and ‐ 1 if not found.

The sample code of Binary search is as follows:

BinarySearch(A[0..N-1], key, low, high) { if (high < low) return -1 // not found mid = (low + high) / 2 if (A[mid] > key) return BinarySearch(A, key, low, mid-1) else if (A[mid] < key) return BinarySearch(A, key, mid+1, high) else return mid // found }

3. Requirements 3.1. Your code must have one main procedure and one binary search procedure. It can have more procedures if needed. 3.2. The code contains one array that holds 16 sorted integers and one integer named “key” as input. The output should be stored in another integer named “position”.

3.3. For binary search procedure (See discussion slides “MIPS Programming(2)” for details about procedures):

a. You must use “jal” to call a procedure.

b. All needed parameters (such as key, low, high and the array/variable addresses) must be passed as arguments by using a0‐a3 or stack.

c. You need to save all necessary registers.

d. It must follow the “binary search” concept. Don’t implement other search mechanisms.

3.4. Good comments are required. In particular:

a. Include a comment block at the top of your program of the form

program2.s

by Your Name

[email protected]

for CDA 3101

FALL,

b. All procedures must have a register map, which described which registers are be ing used by the procedure and their symbolic meaning. c. When it would enhance the understandability of the code, prefix a block of state ments with a comment describing the purpose of that block. d. Each and every assembly statement must be given a good comment that describ es the semantic meaning of the operation being performed (restating the syntac tic meaning doesn’t count). ƒ addi $t4, ‐ 4 # $t4 ‐= 4 BAD! ƒ addi $t4, ‐ 4 # count ‐= 4 GOOD!

3.5. All assignments must be submitted through E‐Learning system. No late submission will be accepted. You are required to submit the MIPS code (in .s format) and, if necessary, a text file (in the format of txt, word, or pdf) explaining the steps you take to implement the program. Please make sure that your submitted file can be opened on CISE windows machines.

3.6 All homework must be done individually.

4. Hints. Read discussion slides “MIPS Programming(2)” carefully.