This lab provides experience with floating point arithmetic operators and functions.
Modify lab 3 in the following ways:

1. Do all calculations using double precision floating point representation. This means that you must do the input and output as type double.

2. Use functions for all calculations. This means that you need a function to calculate the length of the x and y lines, the square of the length of the line between the points and the area of the circle, square and rectangle (5 functions). I did some of this as an example, so I am giving you this code. You do not need to write functions to do the input or output if you don’t want to. The circle, square and rectangle functions should output the results.

3. Do not use the menu from lab 3. Instead, write a main program that consists of getting the four input values, calls the circle function and returns, calls the square function and returns, calls the rectangle function and returns and terminates. The circle, square and rectangle functions will need to call the other functions in order to do their job. Therefore, you will have nested function calls. You will need save some of the return addresses in places other than register $ra. You can do this with the jalr instruction or by using the stack.

4. Test the program using the following data:
x1: 1, y1: 1, x2: 2, y2: 2 Circle Area: 6.2382… Square Area: 2.0 Rectangle Area: 1.0
x1: 3, y1: 5, x2: 7, y2: 9 Circle Area 100.5312… Square Area: 32.0 Rectangle Area: 16.0

This lab provides experience with bit string manipulation and logical operators and functions.

In this lab, all data is to be regarded as bit strings representing subsets of the set {1, 2, … 32}. If the bit string has a 1 in position i, then element i is included in the subset. Therefore, the string: 1000 1001 1100 0000 0000 0010 1000 1110 corresponds to the set: {2, 3, 4, 8, 10, 23, 24, 25, 28, 32}. Write MIPS assembly functions to do the following.

1. Print out a set: I do not care about the format. You can print from smaller to larger or from larger to smaller. I would do a loop that went from 1 to 32 (or from 32 to 1). I would load a masking bit pattern that corresponded to the position number of the loop counter (0x00000001 for 1 or 0x80000000 for 32). Isolate the bit in the operand by using the AND operation. If the result of the AND is not 0 then the loop counter is in the set and should be displayed. Increment (decrement) the counter and shift the masking bit pattern to the left or the right depending on the starting pattern.
2. Determine if an element is a member of a given set.
3. Determine the union of two sets.
4. Determine the intersection of two sets.
To test the program, load the value 0xaaaaaaaa into a register as the first set and the value 0x24924924 into a register as the second set.
Print out each set; determine whether or not 20 is in each set, print the union of the sets and the intersection of the sets.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

msg1 : .asciiz "Enter values x1 y1 x2 y2 below:\n"
msg2 : .asciiz "Area of circle is : "
msg3 : .asciiz "Area of square is : "
msg4 : .asciiz "Area of rectangle is : "
.globl main
# prompt the user to enter the numbers
li $v0, 4 # syscall 4 (print_str)
la $a0, msg1 # string address
syscall # print the string

li $v0, 7 # syscall 7 (read_double)
mov.d $f2, $f0 # move x1 to $f2

li $v0, 7 # syscall 7 (read_double)
mov.d $f4, $f0 # move x2 to $f4

li $v0, 7 # syscall 7 (read_double)
mov.d $f6, $f0 # move y1 to $f6

li $v0, 7 # syscall 7 (read_double)
mov.d $f8, $f0 # move y2 to $f8

addi $sp, $sp, -32 # make room for 4 doubles
s.d $f2, 24($sp) # push x1 to stack
s.d $f4, 16($sp) # push y1 to stack
s.d $f6, 8($sp) # push x2 to stack
s.d $f8, 0($sp) # push y2 to stack
jal circle # call circle procedure
jal square # call square procedure
jal rectangle # call rectangle procedure
addi $sp, $sp, 32 # restore the stack pointer

li $v0, 10 # syscall 10 (exit)
syscall # exit

.globl length_x_y

By purchasing this solution you'll be able to access the following files:
task6.s and task7.s.

50% discount

$40.00 $20.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Assembly Language Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats