Question

In: Computer Science

1. Write an assembly language program that prompts the user for and reads four integers (x1,...

1. Write an assembly language program that prompts the user for and reads four integers (x1, y1, x2, y2) which represent the coordinates of two points. Make sure you keep track of which number is which.

2. Treat the line between the points as the radius of a sphere and compute the surface area of the sphere. Print the output with a label, such as “The surface area of the sphere is: …”. Hint: The distance between the points is the square root of ((x2 – x1)2 + (y2 – y1)2 ). However, since you have to square the radius, to get the area, you don’t need to worry about the square root. To work with π, do what the text does on page 14. Use 314156 as π and do the calculations. At the end, divide by 100000 and the quotient is your answer. Note that the answer will be an integer, which is fine. Formula: Surface Area = 4πr2

3. Once part 2 is working properly, add code to treat the line between the points as the side of a cube and compute the surface area of the cube. The calculation is similar to what you did in part 2 except for the multiplication by π. Print the output with an appropriate label. Formula: Surface Area = 6*side2

4. Add labels above each of the calculation code segments such (sphere: and cube:). Add a menu to the program that prompts the user as follows: “To quit enter 0” “To calculate the surface area of a sphere enter 1” “To calculate the surface area of a cube enter 2” “Enter your choice:”

# #########################################
This is what i have so far. I cant get the answer for the area of the sphere to print.

Im a beginner at this so can you show what im doing wrong.

######################################################################
   .data
       Prompt1: .asciiz "\nEnter the number for x1: "
       Prompt2: .asciiz "\nEnter the number for x2: "
       Prompt3: .asciiz "\nEnter the number for y1: "
       Prompt4: .asciiz "\nEnter the number for y2: "
       Prompt5: .asciiz "\nTo quit enter 0"
       Prompt6: .asciiz "\nTo calculate the surface area of a sphere enter 1"
       Prompt7: .asciiz "\nTo calculate the surface area of a cube enter 2"
       Prompt8: .asciiz "\nEnter your choice: "
       Prompt9: .asciiz "\nSurface area of sphere: "
       numPI: .double 314156.00
       num4: .double 4.00
       num1: .double 100000.00
   .text
main:
   la $a0,Prompt1
   li $v0,4
   syscall
  
   li $v0,7
   syscall
   mov.d $f2,$f0
  
   la $a0,Prompt2
   li $v0,4
   syscall
  
   li $v0,7
   syscall
   mov.d $f4,$f0
  
   la $a0,Prompt3
   li $v0,4
   syscall
  
   li $v0,7
   syscall
   mov.d $f6,$f0
  
   la $a0,Prompt4
   li $v0,4
   syscall
  
   li $v0,7
   syscall
   mov.d $f8,$f0
  
   la $a0,Prompt5
   li $v0,4
   syscall
  
   la $a0,Prompt6
   li $v0,4
   syscall
  
   la $a0,Prompt7
   li $v0,4
   syscall
  
   la $a0,Prompt8
   li $v0,4
   syscall
  
   li $v0,5
   syscall
  
   beq $v0,$0,end
   end:
   li $v0,10
   syscall
  
   beq $v0,'S',sphere
   sphere:
   #((x2 – x1)2+ (y2 – y1)2)
   sub.d $f10,$f4,$f2 #x2-x1
   sub.d $f12,$f8,$f6 #y2-y1
   mul.d $f10,$f10,$f10 #squared
   mul.d $f12,$f12,$f12 #squared
   add.d $f14,$f10,$f12 #addition
   l.d $f20,num4
   l.d $f22,numPI
   mul.d $f16,$f20,$f22
   mul.d $f16,$f16,$f14
   l.d $f24,num1
   div.d $f16,$f16,$f24 #Surface area of the sphere
   #display Sphere prompt
   la $a0,Prompt9
   li $v0,4
   syscall

   #display Surface Area
   li $v0,3
   syscall
  
  
  

Solutions

Expert Solution

Please find the code below::

.data

prompt: .asciiz "\nEnter choice \n1 For circle\n2 For Square\n3 For rectangle \n0 for exit : " #prompt for string

msg : .asciiz "Invalid choice try again."

msg1 : .asciiz "Enter value x1 y1 x2 y2 below \n"

msg2 : .asciiz "Area of circle is : "

msg3 : .asciiz "Area of square is : "

msg4 : .asciiz "Area of rectangle is : "

.text

loop: #loop for user choice

li $v0,4

la $a0,prompt #it will print prompt

syscall

li $v0,5

syscall #ask user input

move $t1,$v0 #store A in t1

#based on input jump to location

beqz $t1,exit

beq $t1,1,circle

beq $t1,2,square

beq $t1,3,rectangle

#if not any option show error

li $v0,4

la $a0,msg #it will print prompt

syscall

j loop

circle:

li $v0,4

la $a0,msg1 #it will print prompt

syscall

li $v0,5

syscall #ask user input

move $t1,$v0 #store A in t1

li $v0,5

syscall #ask user input

move $t2,$v0 #store A in t1

li $v0,5

syscall #ask user input

move $t3,$v0 #store A in t1

li $v0,5

syscall #ask user input

move $t4,$v0 #store A in t1

#values stored in t1 t2 t3 t4

sub $s0,$t1,$t3 #x2-x1

sub $s1,$t2,$t4 #y2-y1

mul $s0,$s0,$s0 #square

mul $s1,$s1,$s1 #square

add $s2,$s0,$s1 #add

mul $s2,$s2,314156 #mul by pi

div $s2,$s2,100000 #divide by 100000

li $v0,4

la $a0,msg2 #it will print prompt

syscall

li $v0,1

move $a0,$s2

syscall

j loop #loop for next

#same for square

square:

li $v0,4

la $a0,msg1 #it will print prompt

syscall

li $v0,5

syscall #ask user input

move $t1,$v0 #store A in t1

li $v0,5

syscall #ask user input

move $t2,$v0 #store A in t1

li $v0,5

syscall #ask user input

move $t3,$v0 #store A in t1

li $v0,5

syscall #ask user input

move $t4,$v0 #store A in t1

sub $s0,$t1,$t3

sub $s1,$t2,$t4

mul $s0,$s0,$s0

mul $s1,$s1,$s1

add $s2,$s0,$s1

li $v0,4

la $a0,msg3 #it will print prompt

syscall

li $v0,1

move $a0,$s2

syscall

j loop

#same for rectangle

rectangle:

li $v0,4

la $a0,msg1 #it will print prompt

syscall

li $v0,5

syscall #ask user input

move $t1,$v0 #store A in t1

li $v0,5

syscall #ask user input

move $t2,$v0 #store A in t1

li $v0,5

syscall #ask user input

move $t3,$v0 #store A in t1

li $v0,5

syscall #ask user input

move $t4,$v0 #store A in t1

sub $s0,$t1,$t3

sub $s1,$t2,$t4

mul $s2,$s0,$s1

li $v0,4

la $a0,msg4 #it will print prompt

syscall

li $v0,1

move $a0,$s2

syscall

j loop

exit:


Related Solutions

1. Write a program that prompts the user for a filename, then reads that file in...
1. Write a program that prompts the user for a filename, then reads that file in and displays the contents backwards, line by line, and character-by character on each line. You can do this with scalars, but an array is much easier to work with. If the original file is: abcdef ghijkl the output will be: lkjihg fedcba Need Help with this be done in only PERL. Please use "reverse"
Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
Must use AT&T x64/GNU Assembly syntax. Write an assembly language program that reads in two integers,...
Must use AT&T x64/GNU Assembly syntax. Write an assembly language program that reads in two integers, A and B, and uses them to compute the following expressions. You must use the same values for A and B throughout all three expressions. 1) A * 5 2) (A + B) - (A / B) 3) (A - B) + (A * B)
Write an assembly language program that repeatedly prompts the user to enter signed decimal integer numbers....
Write an assembly language program that repeatedly prompts the user to enter signed decimal integer numbers. The program should be run from the command prompt, output a text prompt to the screen, and then wait for the user to type in a number followed by the Enter key. (The legitimate range of user input values is any signed integer that can be represented in 32 bits.) After each number is entered, the program should determine and display the following information...
C Program 1. Write a program that prompts the user to enter 3 integers between 1...
C Program 1. Write a program that prompts the user to enter 3 integers between 1 and 100 from the keyboard in function main and then calls a function to find the average of the three numbers. The function should return the average as a floating point number. Print the average from main.The function header line will look something like this:float average(int n1, int n2, int n3) STOP! Get this part working before going to part 2. 2. Create a...
Write a MIPS assembly program that prompts the user first for a string, then for a...
Write a MIPS assembly program that prompts the user first for a string, then for a character. The program should then search the string for the character and print out the number of times the character appears in the string. You can use as many restrictions as you want, just be sure to list them. You must allocate space in the .data segment of your program for the user string.
Question: Write a program in python that reads in the file climate_data_2017_numeric.csv and prompts the user...
Question: Write a program in python that reads in the file climate_data_2017_numeric.csv and prompts the user to enter the name of a field (other than Date), and then outputs the highest and lowest values recorded in that field for the month of August. The file climate_data_2017_numeric.csv contains the following fields: Date Minimum temperature (C) Maximum temperature (C) Rainfall (mm) Speed of maximum wind gust (km/h) 9am Temperature (C) 9am relative humidity (%) 3pm Temperature (C) 3pm relative humidity (%) Expected...
Write a program that prompts user to enter integers one at a time and then calculates...
Write a program that prompts user to enter integers one at a time and then calculates and displays the average of numbers entered. Use a while loop and tell user that they can enter a non-zero number to continue or zero to terminate the loop. (Switch statement) Write a program that prompts user to enter two numbers x and y, and then prompts a short menu with following 4 arithmetic operations: Chose 1 for addition Chose 2 for subtraction Chose...
in C++ programing language Write a program that prompts the user for an integer, then prints...
in C++ programing language Write a program that prompts the user for an integer, then prints all of the numbers from one to that integer, separated by spaces. Use a loop to print the numbers. But for multiples of three, print "Fizz" instead of the number, and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". Drop to a new line after printing each 20 numbers. If the user typed...
java language NetBeans Write a program that prompts the user to enter the weight of a...
java language NetBeans Write a program that prompts the user to enter the weight of a person in kilograms and outputs the equivalent weight in pounds. Output both the weights rounded to two decimal places. (Note that 1 kilogram = 2.2 pounds.) Format your output with two decimal places.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT