Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Practice Problem [no points]: You should read and understand Fibonacci algorithm, write a code in a high level language of your choice and in Assembly

Practice Problem [no points]: You should read and understand Fibonacci algorithm, write a code in a high level language of your choice and in Assembly to find a Fibonacci number and check your result. At the end of this assignment a possible solution to this problem is given both in Python and MIPS assembler. Note that it would have been possible to write the Python differently to achieve the same function. 1. [20 points] Write and debug a MIPS program that computes factorial of a given number iteratively (not recursively). This is a MIPS program with looping. Instructions and Hints: Begin by writing the factorial calculation in your favorite high-level programming language and including the entire program as a comment in your MIPS program like the Python code as in the practice problem. Your high-level code must work correctly for any value from 0! upward (remember that 0! =1 by definition) for answers that will fit in 32 bits. Your high level language implementation and your MIPS implementation must use the SAME algorithm (same type of loop, same number of and location of branches, no try statements etc.) You will want to use an algorithm that will minimize the number of branches necessary to make the assembly version simpler. Evaluation: Your code should be appropriately commented. 25% will be deducted if the high-level language code is not in a comment as specified above. The output from your run should look similar to (though obviously not identical to) the Fibonacci output. 2. [EXTRA CREDIT 5 points] Implement a program to calculate the 2's complement of a number entered by the user. The program should only use the XOR and ADD operators. Your program should include a proper and useful prompt for input, and print the results in a meaningful manner, similar to above. Submission (15 points): Submit the following to D2L before the deadline: a. Assembly Source code. (filename format: firstnameLastname_X.s), where X is the problem number above a. PDF document containing screen shots of output of your program with three different data inputs pasted in a word file. (filename format: firstnameLastname_X.pdf), where X is the problem number above Formatting Information (See the code in practice lab 01 as an example) Read the following information/instructions before you start. Comment your code explain the logic of your code. Initial comments in your code must include: # Your name # IT 320 Assignment 3 # I certify that this program is entirely my own creation. # I have not shared this code with any other person. You will need to use .text and .data directives to define program and data areas in SPIM. A colon (:) must follow all labels. Note that labels allow easy reference to a specific address/place in the program or an argument that is required. Each data entry must be uniquely labeled to avoid any potential error. The word "main:" must label the first line in a SPIM program and always be made global. You may write only one instruction to a line (once past the instruction, you may add a comment, simply preceding with a # sign). Read the resources posted on D2L for a full list of directives and instruction set. All characters in a string are represented in ASCII code. Use comments (#) to adequately write the logic of the program. Note comments do not wrap. If a comment takes more than one line, start a new line with # and continue your comment. A "syscall 10" to return control to OS. For example, li $v0, 10 syscall For better readability well format your code: o use distinct columns for labels, opcode, operands and comments (see the format in the example below). Always read the assignment specification, where most hints to write the code is provided. IMPORTANT Certification required for all programming assignment submissions Your program must be written exclusively by you. It is acceptable to discuss logic and other strategies such as the number of variables, number of functions, et cetera, but it is NOT acceptable to show another class member even a single line of code. Obviously, using code that I provide is acceptable. The program must contain the following comment lines immediately after the comment(s) containing your name: # I certify that this program is entirely my own creation (except for portions provided # to me by the professor). # I have not shared this code with any other person. Protect your code. If another student obtains a copy of your program even though you are unaware of the infraction, you are still guilty of collusion. Do not leave an ACC workstation unattended, even for a little while. Other students monitor your patterns and, while you are out for even a few seconds, may walk up to your workstation and email a copy of your program to themselves! You should also be careful where you leave paper copies of your program. A trash receptacle anywhere near the ACC is likely to be rummaged. You should also protect your work in situations where you are living with someone else taking the class or a friend of someone who is taking the class. # Python code for the iterative Fibonacci algorithm: # i=int(raw_input("Which fibonacci number do you want? ")) # a=0 # two variables to hold the generating values # b=1 # c=0 # count of how far we have iterated # while (c < i): # t = a # a temporary to hold the old value of a # a = b # b = t + b # c += 1 # print "Fibonacci #", c, "is", a .data p1: .asciiz "Which Fibonacci number do you want? " p2: .asciiz "Fibonacci # " p3: .asciiz " is " nl: .asciiz " " .text .globl main # must be global main: li $v0, 4 # system call code for print_str la $a0, p1 # address of string to print syscall # print the first prompt li $v0, 5 # system call code for read_int syscall # read the integer move $t0, $v0 # and store "i" move $t1, $zero # initialize "a" li $t2, 1 # initialize "b" move $t3, $zero # initialize "c" loop: bge $t3, $t0, done # while c < i branch to done if t3 >= t0 move $t4, $t1 # t = a move $t1, $t2 # a = b add $t2, $t2, $t4 # b = t + b addi $t3, $t3, 1 # c += 1 b loop # branch unconditionally to loop done: li $v0, 4 # system call code for print_str la $a0, p2 # address of string to print syscall # print the answer part 1 li $v0, 1 # system call code for print_int move $a0, $t3 # integer to print (c) syscall # print it li $v0, 4 # system call code for print_str la $a0, p3 # address of string to print syscall # print "is" li $v0, 1 # system call code for print_int move $a0, $t1 # integer to print (a) syscall # print it li $v0, 4 # system call code for print_str la $a0, nl # address of string to print syscall # print some newlines jr $ra # return to system

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions