Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
kjc015
CSCI206-S21-62
Commits
21b36538
Commit
21b36538
authored
Mar 15, 2021
by
kjc015
Browse files
Prelab Complete
parent
21c3495f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Labs/Lab06/Makefile
0 → 100644
View file @
21b36538
all
:
collatz
CC
=
gcc
CFLAGS
=
-Wall
-Werror
collatz
:
collatz.o
$(CC)
$(CFLAGS)
collatz.o
-o
collatz
Labs/Lab06/collatz.c
0 → 100644
View file @
21b36538
#include
<stdio.h>
#define MAX_ITEMS 100
int
collatz
(
int
n
)
{
if
(
n
==
1
){
return
n
;
}
if
(
n
%
2
==
0
){
return
n
/
2
;
}
if
(
n
%
2
==
1
){
return
3
*
n
+
1
;
}
return
0
;
}
int
find_length
(
int
n
)
{
int
count
=
0
;
if
(
n
==
1
){
count
=
1
;
return
count
;
}
else
{
count
=
1
;
while
(
n
>
1
){
count
++
;
n
=
collatz
(
n
);
}
return
count
;
}
}
int
main
(
void
)
{
int
i
;
for
(
i
=
1
;
i
<
MAX_ITEMS
;
i
++
){
printf
(
"%d ==> %d
\n
"
,
i
,
find_length
(
i
));
}
return
0
;
}
Labs/Lab06/prelab.s
0 → 100644
View file @
21b36538
#
File
:
prelab
.
s
#
CSCI
206
#
Lab
06
#
Spring
2020
#
Originally
by
Professor
Guattery
and
Professor
Meng
in
spring
2011
#
Revised
:
Xiannong
Meng
#
02/20/2016
#
2019-11-04
for
RISC
-
V
#
#
Student
name
:
#
#
This
simple
program
demonstrates
writing
very
simple
leaf
procedures
.
#
The
program
computes
an
expression
in
the
form
of
"4x - (2y + C)"
.
#
You
are
to
the
procedure
"myFunc"
,
taking
two
parameters
(
x
and
y
)
and
#
produce
"4x - (2y + C)"
within
the
procedure
.
#
See
detailed
instructions
in
lab
handout
.
.
data
#
Define
the
constant
c
here
C
:
.
word
1
.
text
#
The
main
()
procedure
calls
my_func
twice
,
storing
the
results
into
s0
and
s1
main
:
#
Call
my_func
(
2
,
3
)
storing
result
in
s0
[
s0
=
4
*
2
-
(
2
*
3
+
1
)
=
1
]
addi
a0
,
zero
,
2
#
load
2
(
x
)
into
a0
addi
a1
,
zero
,
3
#
load
3
(
y
)
into
a1
jal
my_func
add
s0
,
zero
,
a0
#
store
result
in
s0
#
Call
my_func
(
5
,
6
)
storing
result
in
s1
[
s1
=
4
*
5
-
(
2
*
6
+
1
)
=
7
]
addi
a0
,
zero
,
5
addi
a1
,
zero
,
6
jal
my_func
add
s1
,
zero
,
a0
#
#
Add
code
here
to
print
the
result
of
my_func
(
2
,
3
)
+
my_func
(
5
,
6
)
#
add
a0
,
s1
,
s0
li
a7
,
1
ecall
#
The
program
is
finished
.
Tell
the
"Operating System"
that
we
wish
to
exit
.
#
We
'll learn more about this syntax later this week
addi
a7
,
zero
,
10
#
system
call
for
exit
ecall
#
my_func
=
4
x
-
(
2
y
+
C
)
#
Because
this
function
modifies
only
a0
,
there
is
no
need
#
to
create
an
activation
frame
my_func
:
#
#
your
code
for
the
procedure
goes
here
#
li
s3
,
0
li
t0
,
4
li
t1
,
2
la
t5
,
C
lw
s3
,
0
(
t5
)
mul
t2
,
t0
,
a0
mul
t3
,
t1
,
a1
add
t4
,
t3
,
s3
sub
t6
,
t2
,
t4
mv
a0
,
t6
jr
ra
#
0040000C
-
Line
55
#
0040001C
-
Line
67
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment