Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AM-pa1 #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ Fibonacci numbers, it prompts the user how many numbers to print. (You
can do this by keeping the array the same size, and limiting the user
to input sizes only up to 9.)

How big of an output do you want?
500
Please enter a number 1-9
How big of an output do you want?
0
Please enter a number 1-9
How big of an output do you want?
3
The Fibonacci numbers are:
1 1 2
-- program is finished running --

=======================================================

PART TWO. 40 points.
Expand All @@ -63,6 +75,17 @@ Write a MIPS Assembly program that performs the following tasks, in order:
4. For each computed result, retrieve it from memory and print it to the terminal.

5. Print a concluding message and exit.
Input two integers.
100
200

Adding...........
300
Subtracting......
-100
Multiplying......
20000
Bye...............

======================================================

Expand All @@ -73,8 +96,8 @@ Write a MIPS Assembly program that performs the following task:
Calculate the sum of the odd integers between 1 and 15, inclusive.
(You may use a MIPS version of a while-loop to complete this task.)

Store each partial sum in memory as you go. I.e., store 1+3=5 in memory. Then store that result plus the next odd number (5+5=10, then 10+7=17), and so on.
Store each partial sum in memory as you go. I.e., store 1+3=4 in memory. Then store that result plus the next odd number (5+5=10, then 10+7=17), and so on.

Load the final result into a register and print the result to the terminal.


64
32 changes: 26 additions & 6 deletions fibonacci.asm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# COMP3410 Program Template
# Author: Your Name
# Assignment: PA[X]
# Date: Date of submission
# Author: Aaron Marshall
# Assignment: PA[1] part 1
# Date: 2/10/14

# Turn in one .asm file per assignment component
# Remember to submit it as a pull request to the GitHub repo for the assignment
Expand All @@ -18,11 +18,23 @@

fibs: .word 0 : 9 # create an array variable named "fibs" of 9 word-length elements (4 bytes each)
size: .word 9 # create a single integer variable named "size" that indicates the length of the array
input: .asciiz "How big of an output do you want?\n"
errort: .asciiz "Please enter a number 1-9\n"

###############################################
# .text segment. Assembly instructions go here.
###############################################
.text
begin: la $a0, input #load input
li $v0, 4 #get ready to output text
syscall

li $v0, 5 #load user input
syscall
add $a1, $zero, $v0 #adds number input to address
bgt $a1, 9, error #checks for invalid
blt $a1, 1, error #checks for invalid

la $s0, fibs # load address of array into $s0
la $s5, size # load address of size variable into $s5
lw $s5, 0($s5) # load array size from its address in the register
Expand All @@ -44,12 +56,20 @@ loop: lw $s3, 0($s0) # Get value from array fibs[i-2]

# Now the Fibonacci numbers are computed and stored in array. Print them.
la $a0, fibs # first argument for print (array)
add $a1, $zero, $s5 # second argument for print (size)
#add $a1, $zero, $s5 # second argument for print (size)
jal print # call print routine (note the 'print' label on line 68)

# The program is finished. Exit.
li $v0, 10 # system call for exit
syscall
syscall

error: la $a0, errort #gets read to output text
li $v0, 4
syscall

j begin # goes back the start



###############################################################
# Subroutine to print the numbers on one line. Another .data segment.
Expand All @@ -64,7 +84,7 @@ head: .asciiz "The Fibonacci numbers are:\n" # Print a little helpful intro
###########################################################

.text

print: add $t0, $zero, $a0 # starting address of array of data to be printed
add $t1, $zero, $a1 # initialize loop counter to array size
la $a0, head # load address of the print heading string
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job, program works well under all test cases.

Expand Down
20 changes: 20 additions & 0 deletions looper.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# COMP3410 Program Template
# Author: Aaron Marshall
# Assignment: PA[1] part 3
# Date: 2/10/14
#adds odd 1-15
.text

li $s0, 1 #1
addi $s1, $s0, 2 #3
loop:
add $s0, $s1, $s0 # s0 + s1
addi $s1, $s1, 2 #s1+2
ble $s1, 15, loop # starts loop if <= 15

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-6 Instructions require that you store partial sum in memory and retrieve it each time you add a number to it.

add $a0,$zero, $s0 #prints final answer
li $v0, 1
syscall

li $v0, 10 #exits
syscall
58 changes: 58 additions & 0 deletions part2.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# COMP3410 Program Template
# Author: Aaron Marshall
# Assignment: PA[1] part 2
# Date: 2/10/14
# takes two inputted number and adds, subs, and mults
.data
input: .asciiz "Input two integers.\n"
subtext: .asciiz "\nSubtracting......\n"
addtext: .asciiz "\nAdding...........\n"
multitext: .asciiz "\nMultiplying......\n"
goodbye: .asciiz "\nBye..............\n"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-4 Instructions require a printed introduction including name, title, and purpose of program

.text
la $a0, input #output of input text
li $v0, 4
syscall

li $v0, 5 #it wants a number
syscall
add $s0, $zero, $v0 #adds number to register

li $v0, 5 #get the second number
syscall
add $s1, $zero, $v0 #adds sec. to register

la $a0, addtext #prints the addtext
li $v0, 4
syscall

add $s2, $s0, $s1 # does the math then prints the result
add $a0, $s2, $zero
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-8 Instructions require that your calculations be stored in memory and retrieved from memory for printing.

li $v0, 1
syscall

la $a0, subtext #prints the subtext
li $v0, 4
syscall

sub $s3, $s0, $s1 #does subtraction and prints answer
add $a0, $s3, $zero
li $v0, 1
syscall

la $a0, multitext #prints multitext
li $v0, 4
syscall

mul $s4, $s0, $s1 #multiplies and prints answer
add $a0, $s4, $zero
li $v0, 1
syscall

la $a0, goodbye #prints the bye message
li $v0, 4
syscall

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-4 Instructions require a printed concluding message.

li $v0, 10 #exits
syscall