0% found this document useful (0 votes)
98 views16 pages

Proj 1

This document describes a MIPS assembly language project that solves algebraic expressions without using multiplication, division, or shifting functions. It takes four positive integers as input from the user and uses recursive addition and subtraction to calculate the expressions. It multiplies values through repeated addition and divides through repeated subtraction. Once the expressions are solved, the results are printed to the user in both decimal and binary formats. The program design, register usage, labels, and learning outcomes are then explained.

Uploaded by

Banana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views16 pages

Proj 1

This document describes a MIPS assembly language project that solves algebraic expressions without using multiplication, division, or shifting functions. It takes four positive integers as input from the user and uses recursive addition and subtraction to calculate the expressions. It multiplies values through repeated addition and divides through repeated subtraction. Once the expressions are solved, the results are printed to the user in both decimal and binary formats. The program design, register usage, labels, and learning outcomes are then explained.

Uploaded by

Banana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

22/02/17 Project 1 William Toledo

Project 1
William Toledo
William.Toledo@knights.ucf.edu
EEL 3801: Computer Organization
Due Date 22/02/17 | Turned in 22/02/17

1.0 Project Description


The objective of this project was to solve algebraic expressions without the use of multiplication,
PAGE 1 OF 16
22/02/17 Project 1 William Toledo

division, or shifting functions in MIPS. The user would input four positive integers, and the
program use those values to solve the algebraic expressions. The multiplication was
accomplished through recursive addition, and the power functions were done by recursive
multiplication (through the aforementioned addition.) Similarly, the quotients and remainders
were solved through recursive subtraction. Once the final results are found, they are displayed to
the user in decimal (base ten) and in binary (base two.)

2.0 Program Design


The program design revolves around two distinct but similar processes: multiplication by
recursive addition, and division by recursive subtraction. The multiplication by addition function
takes two inputs, the multiplicand and the multiplier. A counter is set to the value of the
multiplier, and a new register is cleared for the recursive addition of the multiplicand. This
register will be known as the partial sum. While the counter is greater than zero, the multiplicand
is added to the partial sum and the counter is decremented. This will result in the product where
partial sum is. Note, when the multiplier and the multiplicand are the same, this results in a
square on the value. After this, we move onto the exponentials since the multiplication also
includes the power functions, for a more condensed code. Another counter is set to one less than
the expected power. (This is because the previous loop accounts for squaring the value.) While
the second counter is greater than zero; the partial sum will be moved to the multiplicand, the first
counter will be reset to the multiplier, and the partial sum will be cleared. Once both loops are
done, the result is once again passed through the function if multiplied by a hard coded integer,
making sure to clear the partial sum.

PAGE 2 OF 16
22/02/17 Project 1 William Toledo

Division by recursive subtraction is very similar to the multiplication by addition described


above. The dividend (numerator in a fraction) is stored in a register known partial difference. The
first (and only) counter is set zero. While this partial difference is greater than zero, subtract the
divisor (denominator) from the partial difference and increment the counter. Once the partial
difference is negative, the counter is decremented once and the divisor is added to the partial
difference. This is to account for doing the loop once too many times. The final counter will be
the quotient and final partial difference will be the remainder.

PAGE 3 OF 16
22/02/17 Project 1 William Toledo

The very first step of the program is to receive the inputs are taken from the user and stored in
their specific registers. The inputs are then passed through the multiplication and division
functions described above, in accordance with the hardcoded algebraic expressions. Seeing as
inputs could also be negative, the absolute values were used in the above functions, and the signs
were taken into account afterwards. If an odd integer was raised to an odd power, a flag would be
set. That flag would later be used to distinguish whether the product would be added or subtracted
from the final algebraic expression. An odd integer raised to an even power is the same as the
absolute value raised to the same even power. After all the products were found and
added/subtracted to the final expressions, then these numbers were stored in a safe register and all
other registers were wiped. Following this, the algebraic expression containing division were
solved. Finally, all the values are printed to the output screen. Expressions f and g are printed in
decimal and in binary, while the quotient of h, and the remainders of h and i were printed only in
decimal. The flowcharts are split up in sections for clarity.

PAGE 4 OF 16
22/02/17 Project 1 William Toledo

PAGE 5 OF 16
22/02/17 Project 1 William Toledo

PAGE 6 OF 16
22/02/17 Project 1 William Toledo

3.0 Symbols Table


Table 1: Registers Used
Register Use

$a0 syscall parameter, holds address of strings to be printed

$v0 syscall parameter, decides the syscal to be executed. Holds integers from user.

$t0 counter for multiplication by recursive addition, then remainders (for h and i)

$t1 storage for A, then f

$t2 storage for B, then g

$t3 storage for C, then f+g

$t4 storage for D,then h_qoutient

$t5 storage for adding (absolute of multiplier), & for subtracting (absolute of dividend)

$t6 storage for adding (absolute of multiplicand)

$t7 variable f, then g - used to add after loops, then sign flag

PAGE 7 OF 16
22/02/17 Project 1 William Toledo

$t8 temporarily hold f while finding g

$t9 counter for powers by recursive multiplication

Table 2: Labels Used


Label(s) Use

F#, G# Multiplication while loop markers. F# is the initial point for the first while
loop (Multiplication by addition) of F, and G# is that of G. # can be 1, 2, 3,
or 4

powF#, powG# Multiplication while loop markers. powF# is the exit of the first nested
while loop (Multiplication by addition) and the start of the second while
loop (power by multiplication) of F, and powG# is that of G. # can be 1, 2,
3, or 4

exF#, exG# Multiplication while loop markers. exF# is the exit of the second while loop
(power by multiplication) of F, and exG# is that of G. # can be 1, 2, 3, or 4

Label(s) Use

F#int, G#int Multiplication while loop markers. F#int is the initial point for the first
while loop by an integer (Multiplication by addition) of F, and G#int is that
of G.# can be 1, 2, 3, or 4

exF#int, exG#int Multiplication while loop markers. exF#int is the exit of the second while
loop by an integer (power by multiplication) of F, and exG#int is that of G.
# can be 1, 2, 3, or 4

F#sign, G#sign Flags for positivity. F#sign is the starting point of a sign check to decide
whether to add or subtract values to F, and G#sign is that of G. # can be 1,
2, 3, or 4

exF#sign, Flags for positivity. exF#sign is the exit point of a sign check to decide
exG#sign whether to add or subtract values to F, and exG#sign is that of G. # can be
1, 2, 3, or 4

H, I Division while loop markers. H is the initial point for the while loop
(division by subtraction) to find h, and I is that of i.

Hrem, Irem Division while loop markers. H is the exit point for the while loop (division
by subtraction) to find h, and I is that of i. Marks a correction stage.

printh, printi printh, flag to negate h if f XOR g is negative. printi flag to negate h if
(f+g) XOR h is negative. Then prints value.

printhr, printir printhr, flag to correct h_rem if f XOR g is negative. printi flag correct
h_rem if (f+g) XOR h is negative. Then prints value.

PAGE 8 OF 16
22/02/17 Project 1 William Toledo

giszero, hiszero Checks for division by zero. Prints error message. Terminates the program.

div0h, div0i Holds string for error message when division by zero occurs.

out, f10, f2, g10, Hold strings for printing.


g2, hq, hr, im, n

end Terminates program using syscall.

4.0 Learning Coverage


This Project emphasized the way that MIPS and other assemblers use memory. In MIPS, only
two values can be processed in an instruction, and the output register must always be
specified. Memory management became a crucial component when there are only ten
temporary registers to use, and four had to be reserved initially for the user input. Another
excellent lesson learned from this Project is that it is important to keep track of which
registers are used for which operations. An organized and well commented program is easier
to debug than a chaotic program with little comments. Another great habit learned from this
project is to clear registers when done using them. This goes hand in hand with organization,
and will assure that no incorrect functions are resulted from dirty memory. Finally, a lesson
that is critical is to thoroughly test the program while creating it. Many cases arose where the
program would behave in an unexpected manner. Frequent testing makes it easier to come up
with solutions to the problems as they arise.

5.0 Prototype in C-language


#include <stdio.h>

#include <stdlib.h>

int i, j, A, B, C, D, sum, f, g, part, h, i, q, r, dif, hq, ir;

int main(){
PAGE 9 OF 16
22/02/17 Project 1 William Toledo

printf("Enter 4 integers for A,B,C,D respectively:\n");

scanf("%d%d%d%d", &A,&B,&C,&D);

f = AddBySum(A, A, 4);

part = AddBySum(B, B, 3);

part = AddBySum(part, 4, 1);

f += AddBySum(A, A, 4);

/// Rest of f then g

hq = DivBySub(f, g);

ir = DivBySub (f+g, hq);

printf("f_10 = %d\n", f);

printf("g_10 = %d\n", g);

printf("h = %d\n", hq);

printf("i_mod = %d\n", ir);

system("PAUSE");

return 0;

int MultByAdd (int multa, int multb, int power){


PAGE 10 OF 16
22/02/17 Project 1 William Toledo

i = abs(multa);

j= power;

while (j>=1){

while(i>0){

sum += abs(multb);

i--;

i=abs(multa);

multb = sum;

sum = 0;

return multb;

int DivBySub (int num, int denom){

dif = abs(num);

i= 0;

while(dif>0){

dif -= abs(denom);

i++;

q = dif + abs(denom);

r = i--;

return q;

PAGE 11 OF 16
22/02/17 Project 1 William Toledo

6.0 Test Plan


The test plan includes using different inputs in MIPS and comparing them to the results from
Excel. The first set of inputs chosen were the ones given in the project instructions ( 15, 9, 21, 3).
These were a simple way to verify that the program worked as intended. The second set of
integers (23, 6, 18, 7) were chosen to purposefully get a value for I_mod. The third set of integers
(-15, -9, -21, -3) were chosen to how the program would function with negative numbers and if
the corrections to the program resulted in the correct results. The fourth set of integers (6, 6, 6, 6)
were chosen to see how the program would behave if I_mod resulted in division by zero (h = 0).
Similarly, the fifth set of numbers (-8, 7, 7 2) were chosen to see how the program would behave
if H_mod resulted in division by zero (g = 0). A final case was to use floating point numbers for
the inputs.

7.0 Test Results


Table 3: Calculation in Excel
A B C D F G H H_mod I_mod

15 9 21 3 49026 13122 3 9660 0

23 6 18 7 279935 111960 2 56015 1

-15 -9 -21 -3 54870 -13122 -4 -10740 0

6 6 6 6 528 7992 0 528 #DIV/0!

-8 7 7 2 2867 0 #DIV/0! #DIV/0! #DIV/0!

15.1 9.2 7.6 2.6 49041.89 2293.25 21 883.559 11.142

PAGE 12 OF 16
22/02/17 Project 1 William Toledo

Table 4: Calculation in MARS


A B C D F G H H_mod I_mod

15 9 21 3 49026 13122 3 9660 0

23 6 18 7 279935 111960 2 56015 1

-15 -9 -21 -3 54870 -13122 -4 -10740 0

6 6 6 6 528 7992 0 528 DNE

-8 7 7 2 2867 0 DNE DNE DNE

15.1 ERROR invalid integer

PAGE 13 OF 16
22/02/17 Project 1 William Toledo

Screenshots of MARS MIPS Run I/O

Set 1 Set 2

Set 3 Set 4

PAGE 14 OF 16
22/02/17 Project 1 William Toledo

Set 5
Set 6

PAGE 15 OF 16
22/02/17 Project 1 William Toledo

8.0 References
8.1 Lecture Slides
EEL3801 Suboh Suboh. They are available on Webcourses.
8.2 Recitation Blog
Recitation Blog available online at http://eel3801.blogspot.com/ provided prototype code.
8.3 MARS Simulator
The MARS Simulator for MIPS processors, available at:
http://courses.missouristate.edu/kenvollmar/mars/and MARS syscall functions listed at:
http://courses.missouristate.edu/kenvollmar/mars/help/syscallhelp.htmlwere used.

PAGE 16 OF 16

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy