Proj 1
Proj 1
Project 1
William Toledo
William.Toledo@knights.ucf.edu
EEL 3801: Computer Organization
Due Date 22/02/17 | Turned in 22/02/17
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.)
PAGE 2 OF 16
22/02/17 Project 1 William Toledo
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
$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)
$t5 storage for adding (absolute of multiplier), & for subtracting (absolute of dividend)
$t7 variable f, then g - used to add after loops, then sign flag
PAGE 7 OF 16
22/02/17 Project 1 William Toledo
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.
#include <stdlib.h>
int main(){
PAGE 9 OF 16
22/02/17 Project 1 William Toledo
scanf("%d%d%d%d", &A,&B,&C,&D);
f = AddBySum(A, A, 4);
f += AddBySum(A, A, 4);
hq = DivBySub(f, g);
system("PAUSE");
return 0;
i = abs(multa);
j= power;
while (j>=1){
while(i>0){
sum += abs(multb);
i--;
i=abs(multa);
multb = sum;
sum = 0;
return multb;
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
PAGE 12 OF 16
22/02/17 Project 1 William Toledo
PAGE 13 OF 16
22/02/17 Project 1 William Toledo
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