Question

In: Computer Science

Lab-3A One-way Conditional Branching Write MIPS assembly code to prompt and read an integer value X,...

Lab-3A One-way Conditional Branching

Write MIPS assembly code to prompt and read an integer value X, and to calculate and display |X|.

Example Input/Output

Enter an integer X : 14

The absolute value is 14

Enter an integer X: -14

The absolute value is 14

Submit a single word document with the:

~MIPS code and screenshots showing:
~ ML code & Registers before execution
~ Input/Output console with at least three test data

(should cover all partitions – one positive number, one negative number, and zero)

Solutions

Expert Solution

Screenshot(Program)

Program

###########################################################
#Create a program to find absolute value
#Of user entered value
###########################################################
.data
   input: .asciiz "Enter an integer X : "
   output: .asciiz "The absolute value is "
#Program starts here
.globl main
.text  
main:
   #Prompt for input
   addi $v0,$0,4
   la $a0,input
   syscall
   #Read input
   addi $v0,$0,5
   syscall
   #Store into a0
   add $a0,$0,$v0
   #Call function to get absolute value
   jal absolute
   #Result in a0
   add $t0,$0,$v0
   #Display output message
   addi $v0,$0,4
   la $a0,output
   syscall
   #Display result
   add $a0,$0,$t0
   addi $v0,$0,1
   syscall
   #Display next line
   addi $a0,$0,10
   addi $v0,$0,11
   syscall

   #Prompt for input
   addi $v0,$0,4
   la $a0,input
   syscall
   #Read input
   addi $v0,$0,5
   syscall
   #Store into a0
   add $a0,$0,$v0
   #Call function to get absolute value
   jal absolute
   #Result in a0
   add $t0,$0,$v0
   #Display output message
   addi $v0,$0,4
   la $a0,output
   syscall
   #Display result
   add $a0,$0,$t0
   addi $v0,$0,1
   syscall

   #End of the program
   addi $v0,$0,10
   syscall

#Implementation of absolute value
absolute:
   #number in v0
   add $v0,$0,$a0
   slt $t0,$0,$v0
   beq $t0,0,negation
   jr $ra
#Convert to positive
negation:
    sub $v0,$0,$v0
    jr $ra

Output


Related Solutions

Write a mips assembly code program that ask the user to enter an integer value, and...
Write a mips assembly code program that ask the user to enter an integer value, and then print the result of doubling that number.
Write a MIPS assembly language to transpose a square integer matrix in code
Write a MIPS assembly language to transpose a square integer matrix in code
Write a MIPS assembly language program to read an arbitrary number of integer pairs from a...
Write a MIPS assembly language program to read an arbitrary number of integer pairs from a file. Each pair will then be multiplied together with the results being accumulated (added together) forming a sum-of-products operation. Submit your report and code here.
Write an assembly code in MIPS program that can read 3 numbers from the user and...
Write an assembly code in MIPS program that can read 3 numbers from the user and print the following: a. The summation b. The average c. The minimum d. The maximum e. Print the values between the minimum and maximum f. Write comments to explain each line in your code -look at Fibonacci code- (no comments mean zero for the assignment ) use MARS MIPS .
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to...
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to the follow java program: int day = (int)(Math.random() * 7); switch (day) { case 1: System.out.println(“Monday”); break case 2: System.out.println(“Tuesday”); break case 3: System.out.println(“Wednesday”); break case 4: System.out.println(“Thursday”); break case 5: System.out.println(“Friday”); break case 6: System.out.println(“Saturday”); break case 0: System.out.println(“Sunday”); break }
write mips assembly mips assembly (x+a) (bx^2+cx+d) using the pesedo- code with loop ,program should claclute...
write mips assembly mips assembly (x+a) (bx^2+cx+d) using the pesedo- code with loop ,program should claclute six T[i] and display aproper message about roots .the the program should store all T[i] as memory array a = [1, 1, 1, 1, 1, 1]; b = [1, 2, 4, 8, 16, 32]; c = [-6, -4, -2, 2, 4, 6]; d = [-1, -3, -5, -7, -9, -11]; for (i=0 ; i<=6; i++) { T[i] =-4 *b [i] * d[i] +c[i] *...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT