Homework 7 | Computer Organization | CDA 3100, Assignments of Electrical and Electronics Engineering

Material Type: Assignment; Professor: Zhang; Class: COMPUTER ORG I; Subject: COMPUTER DESIGN/ARCHITECTURE; University: Florida State University; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 08/31/2009

koofers-user-smd
koofers-user-smd 🇺🇸

9 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Homework #7
Special Note
This assignment has been designated by the Department of Computer Science for
assessment of certain expected outcomes for its degree programs, as required by our
accreditation agencies, the University, and the State of Florida. Departmental policy does
not permit a final grade of "C-" or better to be assigned unless the student has at earned a
grade of "C-" or better on this assignment, regardless of performance on other work in the
course.
The problems were designed by Dr. Stephen P. Leach.
Program 1 (60 points)
A long time ago, a friend of mine showed me a proof having to do with what he
called “Polish” sequences. To generate a Polish sequence, you start with any
positive integer. You square the individual digits of this number and add those
squares, producing the next number in the sequence. This procedure repeats
(theoretically) forever.
Here are some Polish sequences generated for a few positive integers:
308, 73, 58, 89, 145, 42, 20, 4, 16, 37, 58, …
5121, 31, 10, 1, 1, …
27, 53, 34, 25, 29, 85, 89, 145, 42, 20, 4, 16, 37, 58, 89, …
12345678, 204, 20, 4, 16, 37, 58, 89, 145, 42, 20, …
It can actually be proven that the Polish sequence for an arbitrary positive integer
will always terminate in the infinite sequence
1, 1, 1, …
or in the following repeating sequence of eight integers
20, 4, 16, 37, 58, 89, 145, 42, 20, …
Of course, the repeating sequence would not have to begin with 20 … it could
begin with any of the 8 numbers that appear in that sequence.
You are to write a program that will allow us to test this claim. Below, I am
starting you out with a little driver program (this program also appears on the
course website under Course Materials as Polish.asm). I want you to add two
procedures: (1) one called “terms” (called by the main program) whose job is to
pf3
pf4
pf5

Partial preview of the text

Download Homework 7 | Computer Organization | CDA 3100 and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

Homework

Special Note

This assignment has been designated by the Department of Computer Science for

assessment of certain expected outcomes for its degree programs, as required by our

accreditation agencies, the University, and the State of Florida. Departmental policy does

not permit a final grade of "C-" or better to be assigned unless the student has at earned a

grade of "C-" or better on this assignment, regardless of performance on other work in the

course.

The problems were designed by Dr. Stephen P. Leach.

Program 1 (60 points)

A long time ago, a friend of mine showed me a proof having to do with what he

called “Polish” sequences. To generate a Polish sequence, you start with any

positive integer. You square the individual digits of this number and add those

squares, producing the next number in the sequence. This procedure repeats

(theoretically) forever.

Here are some Polish sequences generated for a few positive integers:

It can actually be proven that the Polish sequence for an arbitrary positive integer

will always terminate in the infinite sequence

or in the following repeating sequence of eight integers

Of course, the repeating sequence would not have to begin with 20 … it could

begin with any of the 8 numbers that appear in that sequence.

You are to write a program that will allow us to test this claim. Below, I am

starting you out with a little driver program (this program also appears on the

course website under Course Materials as Polish.asm). I want you to add two

procedures: (1) one called “terms” (called by the main program) whose job is to

display the first 16 terms in a sequence that starts with the value that it is passed

(in $a0) and (2) a function called “Polish” that will be called by the procedure

“terms” … this function will actually calculate and return (in $v0) the next term in

a sequence, given that the current term is the value that is passed to it (in $a0).

Remember that since you have procedures calling other procedures, you need to

be concerned with preserving and restoring certain values on the stack.

Here is the little driver program:

# Your name/date

# Appropriate documentation

# insert your terms procedure and your Polish function here

# Driver program provided by Stephen P. Leach -- written 12/15/

main: la $a0, intro # print intro

li $v0, 4

syscall

loop: la $a0, req # request value of n

li $v0, 4

syscall

li $v0, 5 # read value of n

syscall

ble $v0, $0, out # if n is not positive, exit

move $a0, $v0 # set parameter for terms procedure

jal terms # call terms procedure

j loop # branch back for next value of n

out: la $a0, adios # display closing

li $v0, 4

syscall

li $v0, 10 # exit from the program

syscall

.data

intro: .asciiz "Welcome to the Polish sequence tester!"

req: .asciiz "\nEnter an integer (zero or negative to exit): "

adios: .asciiz "Come back soon!\n"

Start with this code and add your procedures. You may want to add a few items

in the data segment (to assist the terms procedure in producing the appropriate

output), but don’t change the portion of the code that I am providing. Don’t

forget to document your code! We haven’t officially covered some of the needed

arithmetic operations, but the following should be enough information to get you

going (the last two are actually pseudoinstructions):

mul $t1, $t2, $t3 # $t1 = $t2 * $t

div $t1, $t2, $t3 # $t1 = $t2 / $t3 (truncated)

rem $t1, $t2, $t3 # $t1 = $t2 % $t3 (remainder from $t2 / $t3)

Enter a value for x (or 999 to exit): - Our approximation for e^-1.00000000 is 0. Enter a value for x (or 999 to exit): 80 Our approximation for e^80.00000000 is

Enter a value for x (or 999 to exit): 999 Come back soon!

Submit a separate file called exp.asm.

Notes:

You should document your code properly in this homework. You may use the following

code as a template:

Zhenghao Zhang -- 04/10/

newton.asm – a simple program calculating the square root of a given

is number n using singles. The value of the square root of n,

denoted by x, approximated by x=(x+n/x)/2, until the the

absolute value of the difference between new x and the previous

x is smaller than a given threshold such as 1.0E-3.

function main -- written by Zhenghao Zhang -- 04/10/

calling the calsqrt function and display the results

Register use:

$a0 syscall parameter

$v0 syscall parameter

$f0 exp and syscall return value

$f12 exp and syscall parameter

.text .globl main main: li.s $f0, 361. mfc1 $a0, $f jal calsqrt done: mtc1 $v0, $f li $v0, syscall eixt: li $v0, syscall

function calsqrt -- written by Zhenghao Zhang -- 04/10/

calculating the square root of a given number n using singles.

The value of the square root of n, denoted by x, approximated

by x=(x+n/x)/2, until the the absolute value of the difference

between new x and the previous x is smaller than a given

threshold such as 1.0E-3.

Register use:

$a0 parameter from calling routine

$v0 return value

$f0 storing the value of n as a single precision number

$f1 current value of x

$f2 next value of x

$f3 tempory vaiable

$f20 storing constant 2 for dividing

$f21 storing constant 0.001 for exit comparision

calsqrt: addi $sp, $sp, - swc1 $f0, 20($sp) swc1 $f1, 16($sp) swc1 $f2, 12($sp) swc1 $f3, 8($sp) swc1 $f20, 4($sp) swc1 $f21, 0($sp) mtc1 $a0, $f0 # $f0 gets n li.s $f20, 2.0 # $f20 storing constant 2 for dividing li.s $f21, 0.001 # $f21 storing constant 0.001 for exit comparision div.s $f1, $f0, $f20 # $f1 gets n/ calsqrtloop: div.s $f2, $f0, $f1 # $f2 gets n/x add.s $f2, $f2, $f1 # $f2 gets n/x + x div.s $f2, $f2, $f20 # $f2 gets x'=(n/x + x)/ sub.s $f3, $f2, $f1 # $f3 gets x'-x abs.s $f3, $f3 # $f3 gets |x'-x| c.lt.s $f3, $f21 # set the flag if |x'-x| < 0. bc1t calsqrtdone mov.s $f1, $f j calsqrtloop calsqrtdone: mfc1 $v0, $f lwc1 $f0, 20($sp) lwc1 $f1, 16($sp) lwc1 $f2, 12($sp) lwc1 $f3, 8($sp) lwc1 $f20, 4($sp) lwc1 $f21, 0($sp) addi $sp, $sp, 24 jr $ra .data msg_done: .asciiz "done\n"

Your programs will be evaluated using the following criteria:

Proper use of registers and memory (0-8,9-16,17-20)

Proper use of load, store and branch instructions (0-4,5-8,9-10)

Proper use of integer arithmetic instructions (0-4,5-8,9-10)

Proper use of floating point arithmetic instructions (0-4,5-8,9-10)

Proper use of subprogram calls [including use of stack] (0-4,5-8,9-10)

Proper use of return instructions [including use of stack] (0-2,3-4,5-5)

Proper design of a subprogram meet specified requirements (0-8,9-16,17-20)

Proper use of appropriate tools to assemble, test and debug program (0-2,3-4,5-5)

Appropriate documentation (0-4,5-8,9-10)