Concept explainers
I need help writing this code without using ls.i and without li.d because my version of mips does not support those instructions:
please
here is the code:
.data
prompt1: .asciiz "Enter the number of real numbers: "
prompt2: .asciiz "Enter a real number: "
result: .asciiz "The average is: "
.text
.globl main
main:
# Prompt for the number of real numbers
li $v0, 4 # Load the print_string syscall
la $a0, prompt1 # Load address of the first prompt
syscall # Print the prompt
li $v0, 5 # Read an integer syscall
syscall # Get the number of real numbers
move $t0, $v0 # Store the count in $t0
move $t1, $zero # Initialize loop counter to 0
li.s $f0, 0.0 # Initialize floating-point sum to 0.0
input_loop:
beq $t1, $t0, calculate # Exit loop when count reaches input number
# Prompt for each real number
li $v0, 4 # Load the print_string syscall
la $a0, prompt2 # Load address of the second prompt
syscall # Print the prompt
li $v0, 6 # Read a float syscall
syscall # Get the floating-point number
add.s $f0, $f0, $f12 # Add the number to the sum ($f12 holds the input)
addi $t1, $t1, 1 # Increment loop counter
j input_loop # Repeat until all numbers are entered
calculate:
# Calculate the average
mtc1 $t0, $f2 # Move integer $t0 to floating-point register $f2
cvt.s.w $f2, $f2 # Convert integer to float
div.s $f4, $f0, $f2 # Divide sum ($f0) by count ($f2), result in $f4
# Print the result
li $v0, 4 # Load the print_string syscall
la $a0, result # Load the result prompt string
syscall # Print the prompt
mov.s $f12, $f4 # Move the result to $f12 for printing
li $v0, 2 # Print float syscall
syscall # Print the average value
# Exit program
li $v0, 10 # Exit syscall
syscall
to generate a solution
a solution
- My assembly code is having an error in Jdoddle's online assembly compiler. Please tell me whats wrong so I can keep that in mind. Thanks!---- global _mainextern _printfextern _scanf section .data message1 db "Enter first number: ", 0message message2 db "Enter second number:", formatIn db '%d', 0 formatOut db '%d', 10, 0 show db "Sum: ", 0 section .bss firstInt resb 4 secondInt resb 4 section .text_main: push message1 call _printf pop eax push firstInt push formatIn call _scanf pop eax pop eax push message2 call _printf pop eax push secondInt push formatIn call _scanf pop eax pop eax push show call _printf pop eax mov ebx, dword [firstInt] mov ebx, dword [secondInt] add ebx, ecx, push ebx push formatOut call _printfarrow_forwardYour cousin owns an automotive maintenance shop that performs routine maintenance on cars. He has asked you to write a program that will provide a list of services (and their respective prices) to users and allow them to choose any, or all, services they would like and display the final price, including a 34% labor charge, a 14% markup if the car is an import, a 4% Covid-19 Sanitizing fee, and an 9.5% sales tax. Task To accomplish the above, do the following: • Write the two methods outlined below. • Test your program and screenshot your successful test. carMaintenance method This method should accept the make of the car as a parameter (e.g., BMW, Ford, Ferrari, etc.). It should display the services and their prices as follows: Services: Emissions System Repair, Tune Up, Timing Belt Replacement, Transmission Service, respectively: 669.99, 259.99, 885.99, 169.99 These should be stored in parallel arrays. Ask the user to select a service from the list presented for his . Allow the user…arrow_forwardWrite a python program that computes the pay and performs the following tasks: - prompt the user to enter the worked hours; the prompt should use the string "Enter Hours: " - prompt the user to enter the rate; the prompt should use the string "Enter Rate: "- compute the pay-print the pay as: "Pay: Scalculated_pay" - the program should support floating point numbersarrow_forward
- A dual-tone multi-frequency (DTMF) system is used to produce signals that represent the dialed digits in a telephone system. A combination of a horizontal frequency and a vertical frequency is produced whenever a button is pressed on the keypad. The figure below shows a telephone keypad and the different frequencies used. 697 Hz 770 Hz 852 Hz 941 Hz 1209 Hz 1 4 7 1336 Hz 2 1477 Hz 3 5 6 8 9 # 0 * Generate the DTMF tone decoder that will take an audio file the DTMF signal of your student number. The student number must be presented as one complete string (e.g. 2020123456)arrow_forwardFor this problem, you will create a program that calculates the division of two numbers entered by a user. The challenge is that the user can enter anything, even non-numbers like strings. You need to ensure that your program can handle valid and invalid input correctly and provide appropriate feedback to the user without the program crashing. Follow these steps: Prompt the user to enter two numbers, one at a time. You should prompt the user for the first number, get the input, then prompt the user for the second number, and get the input. Store these numbers in variables num1 and num2. Write a function named safe_division that takes in two arguments num1 and num2. This function should perform the division of num1 by num2 and return the result. This function should be able to handle any ValueError or ZeroDivisionError that might occur during the execution and return an appropriate error message. Call your safe_division function with num1 and num2 as arguments. Print the result.…arrow_forwardPython program: Write a program that reads an integer between 0 and 1000 and adds all the digits in the integer. For example, if an integer is 932, the sum of all its digits is 14. (Hint: Use the % operator to extract digits, and use the // operator to remove the extracted digit. For instance, 932 % 10 = 2 and 932 // 10=93) Here is a sample run: Enter a number between 0 and 1000: 999 The sum of the digits is 27arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education