Question

1. Write a program in Assembly language using MIPS instruction set that reads two integer numbers from the user named as star
# # # # # # # # # # # # # # # # # # # # # # # #Start of SQRT Procedure############################### # This procedure return
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thanks.

.data

prompt: .asciiz "\nEnter the start number : " #prompt for string
prompt1: .asciiz "\nEnter the end number : " #prompt for string
newLine: .asciiz "\n" #prompt for string
noPrime : .asciiz "No prime number between numbers A and B" #prompt for string
error1 : .asciiz "Start number must be smaller or equal to the end number."
error2 : .asciiz "Both the number must be positive."
prompt2 : .asciiz "Prime numbers ="

.text
.globl main

main:
askAgain:
li $s4,0

li $v0,4
la $a0,prompt #it will print prompt
syscall
li $v0,5
syscall #ask user input
move $s6,$v0

li $v0,4
la $a0,prompt1 #it will print prompt1
syscall
li $v0,5
syscall #ask user input
move $s7,$v0

blt $s7,$s6,lessError #if t2 less than or equal 0 exit
bltz $s6,zeroError
bltz $s7,zeroError


move $s5,$s6
loop:

move $a0, $s5
jal isPrime               # Send the number to the procedure!
beq $v0,1,prime
j skipPrime
prime:

beq $s4,1,skipMsg
li $v0,4
la $a0,prompt2 #it will print prompt1
syscall
skipMsg:
li $s4,1 #indicator that prime found
move $a0, $s5 #move s1 to a0 for printing
li $v0,1
syscall

li $v0,11
li $a0,',' #it will print new line
syscall


skipPrime:

add $s5,$s5,1 #add m and check condition
ble $s5,$s7,loop

j exit

isPrime:
addi   $t0, $zero, 2               # int x = 2

isPrime_test:
slt   $t1, $t0, $a0               # if (x > num)
bne   $t1, $zero, isPrime_loop      
addi   $v0, $zero, 1               # It's prime!
jr   $ra                       # return 1

isPrime_loop:                       # else
div   $a0, $t0                  
mfhi   $t3                       # c = (num % x)
slti   $t4, $t3, 1              
beq   $t4, $zero, isPrime_loop_continue   # if (c == 0)
add   $v0, $zero, $zero               # its not a prime
jr   $ra                           # return 0

isPrime_loop_continue:      
addi $t0, $t0, 1               # x++
j   isPrime_test               # continue the loop

lessError:
li $v0,4
la $a0,error1 #it will print prompt
syscall
j askAgain

zeroError:
li $v0,4
la $a0,error2 #it will print prompt
syscall
j askAgain


exit:
bnez $s4,primeFound
li $v0,4
la $a0,noPrime #it will print prompt
syscall

primeFound:

output:

lessages Run I/O Enter the start number : 100 Enter the end number : 50 Start number must be smaller or equal to the end numb

Add a comment
Know the answer?
Add Answer to:
1. Write a program in Assembly language using MIPS instruction set that reads two integer numbers...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MIPS Insertion program.........I could really use some help ASAP

    I have this MIPS program and I'm having trouble with it. This program is user inputs numbers until zero and sorts and print the numbers in order. Please soove this issue. You can use any sorting algorithm except bubble sort.  Need it as soon as possible. Here is the code:.datanum: .word 0space: .byte ' ' .text main:  # la $t0, val # loads val into a register  # li $t1, 0      #keeps track of how many numbers entered  la $a0,...

  • Q-1: Write a program in Assembly language using MIPS instruction set that reads 15 integer numbers...

    Q-1: Write a program in Assembly language using MIPS instruction set that reads 15 integer numbers from user and stores all the numbers in the array intArray. Now, read another integer number N from the user, find the total number of array elements that are greater or equal to the number N, and the total number of array elements that are lower than the number N You must have two procedures: i. ReadIntegerArray: this procedure should read integer array elements...

  • 1. Modify larger.s to let the user to enter three numbers and output the largest value...

    1. Modify larger.s to let the user to enter three numbers and output the largest value # larger.s-- prints the larger of two numbers specified # at runtime by the user. # Registers used: # $t0 - used to hold the first number. # $t1 - used to hold the second number. # $t2 - used to store the larger of $t1 and $t2. # $v0 - syscall parameter and return value. # $a0 - syscall parameter. .text main: ##...

  • im trying to complete mips program code about a calculator program that can calculate integer addition...

    im trying to complete mips program code about a calculator program that can calculate integer addition / subtraction written using the MIPS assembler. im having hard times to debug this. The input is given to the array of Formula char (base address $ s0) in the form of a formula. The null character (\ 0, ASCII code 0) is placed at the end. The calculation result is given to the register $ s1 and the overflow is ignored. For example,...

  • WRITE THE FOLLOWING CODE IN FLOATING POINT NUMBERS IN ASSEMBLY LANGUAGE USING MIPS IN MARS .data...

    WRITE THE FOLLOWING CODE IN FLOATING POINT NUMBERS IN ASSEMBLY LANGUAGE USING MIPS IN MARS .data prompt: .asciiz "\nMaximum number is : " prompt1: .asciiz "\nMinimum number is : " prompt2: .asciiz "\nRange of the array is : " size: .word 10 #load array array: .word 23, -12, 45, -32, 52, -72, 8, 13,22,876 .text #load address of array and size la $s4,array #load address of A lw $t0,size #load i to t0 jal getArrayRange li $v0, 4    la...

  • Complete count_bits function. You are given an 32-bits integer stored in $t0. Count the number of...

    Complete count_bits function. You are given an 32-bits integer stored in $t0. Count the number of 1's in the given number. For example: 1111 0000 should return 4 j main ############################################################### # Data Section .data # new_line: .asciiz "\n" space: .asciiz " " double_range_lbl: .asciiz "\nDouble range (Decimal Values) \nExpected output:\n1200 -690 104\nObtained output:\n" swap_bits_lbl: .asciiz "\nSwap bits (Hexadecimal Values)\nExpected output:\n75757575 FD5775DF 064B9A83\nObtained output:\n" count_bits_lbl: .asciiz "\nCount bits \nExpected output:\n20 24 13\nObtained output:\n" swap_bits_test_data: .word 0xBABABABA, 0xFEABBAEF, 0x09876543 swap_bits_expected_data: .word...

  • The task will be to write a program in assembler to enter a number and calculate...

    The task will be to write a program in assembler to enter a number and calculate its associated Fibonacci number using a procedure (subroutine) that is called recursively. Factorial and Fibonacci(outline Programs) # MIPS assembly assembly assemblyassemblycode .data n: .word 4 .text main: la $s0,n lw $a0, 0($s0) jal factorial # move what ever is returned into $a0 move $a0, $v0 li $v0,1 syscall b finished factorial: add $sp , $sp , -8 # make room sw $a0, 4($sp )...

  • Assignment 4 File “quad_sol.s” contains a quadratic polynomial solver, which calculates the integer solution of a quadratic polynomial equation. 1. Rewrite the program using instructions reordering to...

    Assignment 4 File “quad_sol.s” contains a quadratic polynomial solver, which calculates the integer solution of a quadratic polynomial equation. 1. Rewrite the program using instructions reordering to reduce the number of cycles needed to execute the program. Indicate the number of cycle reduction. 2. Describe how forwarding would affect the execution of the program. CODE # quad_sol.s # This assembly program calculates the integer solutions of a quadratic polynomial. # Inputs : The coefficients a,b,c of the equation a*x^2 +...

  • Assignment Develop a program to analyze one or more numbers entered by a user. The user...

    Assignment Develop a program to analyze one or more numbers entered by a user. The user may enter one or more numbers for analysis. Input should be limited to numbers from 1 through 1000. Determine if a number is a prime number or not. A prime number is one whose only exact divisors are 1 and the number itself (such as 2, 3, 5, 7, etc.). For non-prime numbers, output a list of all divisors of the number. Format your...

  • How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++...

    How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++ .data # Defines variable section of an assembly routine. array: .word x, x, x, x, x, x, x, x, x, x # Define a variable named array as a word (integer) array # with 10 unsorted integer numbers of your own. # After your program has run, the integers in this array # should be sorted. .text # Defines the start of the code...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT