0% found this document useful (0 votes)
14 views7 pages

MIPS Floating Point Power Program

This document outlines an assignment to create a MIPS assembly program that computes a floating point number raised to an integer power. It includes learning objectives, specific tasks to complete, and programming standards for documentation and code clarity. The assignment emphasizes input/output operations, algorithm development, and understanding floating point arithmetic in MIPS assembly.

Uploaded by

i200745
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)
14 views7 pages

MIPS Floating Point Power Program

This document outlines an assignment to create a MIPS assembly program that computes a floating point number raised to an integer power. It includes learning objectives, specific tasks to complete, and programming standards for documentation and code clarity. The assignment emphasizes input/output operations, algorithm development, and understanding floating point arithmetic in MIPS assembly.

Uploaded by

i200745
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

Program 4: Making procedures and using floating point arithmetic

in MIPS Assembly

Purpose: This assignment is designed to give you the opportunity to create


a program that will repeatedly ask for a floating point number and an integer
and use a procedure to compute and display the floating point number raised
to the entered integer value.

Learning Objectives: You should be able to perform the following activities


at the end of this assignment:

1. perform input and output operations from the keyboard and to the
screen

2. write an algorithm in pseudocode

3. translate the algorithm from pseudocode into MIPS assembly

4. create procedures and pass parameters in MIPS assembly

5. use floating point operations and understand the problems with


floating point precision

General Knowledge: In addition to the specific skills learned, you should


gain experience in data representation and storage for data in the computer
and the impact of representing values using discrete, binary representations.
Recognize the difference in how processors manage and use floating point
versus integer values.

Specific Tasks:

Write and test a MIPS assembly language program to perform the following
actions in order:

1. Download the [Link] Download [Link]


template for MIPS assembly programs

2. Print a welcome message that include: your name, a title, and a brief
description of the program.

3. Prompt the user to enter a floating point value

4. Prompt the user for an integer power for that floating point number

5. Use a procedure of your design to

1. Compute the floating point value raised to the entered value


2. Display the result of that operation

6. Repeat steps 3 through 5 as long as the user desires to continue

7. Print a farewell message and exit the program gracefully.

Your program should follow these loosely outlined steps in its implementation
(i.e., write the code for step 1, then for step2, etc.).

Enter the value 3.2 for the floating point value and -3 for the integer
exponent. Give a brief explanation of the results you obtain compared to the
results from a scientific calculator. Place this explanation in the comments at
the start of your program.

Assembly Language Programming Standards

Comments are vital in assembly language programming. You will need to


include a header similar to the one included in the MIPS Assembly
template Download MIPS Assembly template. In particular the Pseudocode
section and the register information will help you solidify your understanding
of the program requirements and your method of solution.

You will also need to include comments, whitespace, and blank lines in your
code to make it easy to read and to follow the implementation of the
pseudocode. While one comment per line is not required, you are
encouraged to include enough comments in you code to allow easy tracing
of the pseudocode logic through your assembly implementation (see the
Fibonacci example provided on Canvas).

Programs that do not include sufficient internal documentation via comments


will receive deductions as indicated in the assignment rubric.

Sample Execution

Here is sample output from my solution program (your output may vary).
Submitting your program
You need to submit your complete assembly language program using
Canvas. The only file extension that is accepted is the ".asm" file created by
the MARS program.

Additional Information:

As shown in class, there are several system calls that are available for use in
the MIPS assembly language. These system calls must be used for input and
output in your programs.

To perform a system call:

1. Load the service code in the $v0 register

2. Load any required argument values in $a0, $a1, $a2, or $f12 if the
system call requires them

3. Issue the syscall instruction

4. Use the returned values, if any, from the registers designated in the
command description

Example:

li $v0, 4 # service 4 is print string


la $a0, prompt # load address of string in $a0
syscall # initiate the system call to print the string
MIPS Assembly commands you may need for this assignment:

Arithmetic and Logical:

 add rd, rs, rt Addition with overflow rd = rs + rt

 sub rd, rs, rt Subtraction with overflow rd = rs - rt

 mul rd, rs, rt Multiply without overflow High|Low = rs


x rt and
rd = Low (low order 32-bits of result

 div rs, rt Divide w/out overflow High = remainder


(rs/rt)
Low = quotient (rs/rt) (must test for rt
== 0)

 and rd, rs, rt Perform a bitwise AND rd = rs AND rt

 or rd, rs, rt Perform a bitwise OR rd = rs OR rt

 mul.s rd, rs, rt Perform single precision multiply rd = rs *


rt

 div.s rd, rs, rt Perform single precision divide rd = rs /


rt
Memory Access:

 lw rd, offset(rs) Load word from memory rd = word at [rs


+ offset]
must load address in rs first

 sw rd, offset(rs) Store word into memory word at [rs +


offset] = rd
must load address in rs first

 move rd, rs Move contents of rs into rd rd = rs

 sb rt, offset(rs) Move contents of rt into byte at [rs +


offset]

 lbu rt, offset(rs) Move byte at [rs + offset] into rt, extended
by zeros

 mov.s rd, rs Move single precision rs into rd rd = rs

Other commands:

 syscall Execute the system call identified by $v0 (see


above)

 la rd, label Load the address of label into rd rd = address


of label

 li rd immd Load the numeric value immd into rd rd =


immd

 slt rd, rs, rtb If rs < rt, then rd is set to one

 blt rs, rt, label Branch if less than, if rs < rt, set program
counter to label

 beqz rs, label Branch if equal zero, if rs == 0, set PC to label

 jal label Jump and link, store return address in $ra and
jump to label

 jr rd Jump to address in register rd

Common questions

Powered by AI

The primary challenges of using floating point arithmetic in MIPS assembly include managing precision and handling the representation of floating point numbers, which can lead to precision errors . Addressing these challenges requires careful handling of floating point operations, using appropriate MIPS commands such as 'mul.s' for multiplication and 'div.s' for division, and ensuring that procedures are well-designed to maintain precision . In the context of raising a floating point number to an integer power, one must repeat multiplication while verifying results to prevent significant precision loss, especially when dealing with powers that might lead to very large or very small numbers .

Comments and documentation in MIPS assembly programming are crucial for making code understandable and maintainable. They help trace pseudocode logic through assembly implementations, clarify the purpose of blocks of code, and explain complex instructions or algorithms . Insufficient documentation can lead to deductions in grading rubrics as it obscures the program logic, making it difficult for others (or oneself) to follow and debug the program . Furthermore, well-documented code facilitates collaboration and future modifications or updates .

The register information and pseudocode sections in a MIPS assembly template greatly aid in understanding and meeting program requirements by clearly defining the roles and uses of different registers in the solution, aligning them closely with the program's logical structure . Pseudocode provides a high-level outline, laying down the program's flow, decision-making, and data handling without the complexity of assembly syntax, thus bridging the gap between logic design and implementation . The register information specifies how to efficiently utilize processor resources for tasks like parameter passing and result storage, ensuring adherence to conventions that enhance code reliability and efficiency . This structured approach facilitates problem-solving, reduces errors, and improves program maintainability by providing clear guidance on architecture-specific constraints and best practices .

Testing MIPS assembly programs with specific inputs such as the floating point value 3.2 and integer exponent -3 is essential to verify the correctness and robustness of the algorithms and their handling of corner cases, such as negative exponents or non-integer results . These tests also help illustrate how floating point calculations are managed in terms of precision and rounding errors. Discrepancies between expected results and actual outputs should be clearly documented in code comments. They provide insights into the limitations of floating point operations within MIPS and suggest opportunities for further optimization or understanding of MIPS's precision capabilities .

Creating an algorithm in pseudocode and translating it into MIPS assembly involves several steps. Initially, you define the logical steps and structure of the algorithm in pseudocode, focusing on the high-level flow of operations without regard to specific syntax. This involves detailing input, processing, and output stages . Subsequently, each pseudocode step is translated into corresponding MIPS assembly instructions, using appropriate commands for arithmetic, logic, control flow, and I/O. Particular attention is given to parameter passing in procedures and handling of registers, ensuring that operations are broken down into assembly-compatible tasks while maintaining the logical order and intent of the algorithm .

Procedures in MIPS assembly allow for code reuse and modularity by encapsulating specific functionalities, such as complex arithmetic operations or repeated tasks. Parameter passing is typically managed through registers, where arguments are loaded into specific registers (e.g., $a0, $a1) before the procedure call, and results are typically returned in registers like $v0 . By using conventions for register usage, MIPS ensures that procedures can operate independently and interact with the calling code efficiently, maintaining simplicity in the call and return mechanisms .

Templates in MIPS assembly programming provide a structured starting point for writing code, ensuring that essential components like initializations, system call setups, and routine patterns are established from the beginning . They help in maintaining consistency and serve as educational aids by providing examples of standard practices, such as register usage and memory access patterns. By using templates, learners can focus on implementing the logic and functionalities specific to their tasks, reducing errors that might arise from incorrect setups . They also reinforce the understanding of the assembly language's structural elements, leading to more efficient learning and code development .

The representation of data differs significantly between floating point and integer values in processors like MIPS. Integer values are represented using binary representations that map directly to whole numbers, allowing for exact arithmetic operations. In contrast, floating point values use a scientific notation-like representation that allocates bits for the sign, exponent, and mantissa, resulting in potential precision loss and rounding errors during calculations . This difference impacts how processors manage and use these values, where floating point arithmetic needs special handling to preserve precision and avoid errors during calculations like multiplication or division .

In MIPS assembly, system call instructions for handling string outputs involve using service code 4 to print strings. The implementation includes loading the address of the string into register $a0 and issuing the 'syscall' instruction . Arithmetic operations, while not directly linked to system calls, are performed using logical and arithmetic instructions like 'add', 'sub', 'mul.s', and 'div.s', which handle operations with or without overflow and for both integer and single precision floating points . These instructions are part of MIPS's core assembly language capabilities and require manual management of results and overflow checks in registers .

MIPS assembly handles input and output operations using system calls. The process involves setting up a service code in the $v0 register, loading required argument values into registers like $a0, $a1, $a2, or $f12 if needed, issuing the 'syscall' instruction, and then using any returned values from designated registers . For example, to print a string, one would load the service code 4 into $v0, the string's address into $a0, and then issue the 'syscall' .

You might also like