Write a MIPS Assembly program to accept two numbers A and B from the user. Print all the prime numbers between A and B. Also, check if A and B are prime.
If no prime number exits print the string "No prime number between numbers A and B"
Screenshot
--------------------------------------------------------------
Program
#Data declaration section
.data
lowerBound: .asciiz "Enter A: "
upperBound: .asciiz "Enter B: "
result: .asciiz "Prime numbers are:\n"
Error: .asciiz "Integer should be positive!!!\nPlease enter
again.\n"
BoundCheckError: .asciiz "B should be greater or equal than
A\nPlease enter again.\n"
noPrime: .asciiz "No prime number between numbers A and B\n"
OneDisplay: .asciiz "1 is neither a prime nor a composite
number.\n"
space: .asciiz " "
#main program
.text
main :
#Prompt for first integer
la
$a0,lowerBound
#Address of first input prompt
li
$v0,4
#Systeem call for string display
syscall
#display string
li
$v0,5
#Read integer system call
syscall
#Get integer in v0
move
$s0,$v0
#Store first integer in s0
#Check negative value
ble $s0,0,error1
second:
#Prompt for second integer
la
$a0,upperBound
#Address of second input prompt
li
$v0,4
#Systeem call for string display
syscall
#display string
li
$v0,5
#Read integer system call
syscall
#Get integer in v0
move
$s1,$v0
#Store second integer in s1
#Check negative value
ble $s1,0,error2
#Check upperbound >lowerbound
blt $s1,$s0,boundError
#Result prompt
la
$a0,result
#Address of Error message
li
$v0,4
#Systeem call for string display
syscall
#display string
li
$a1,0
#counter for prime numbere
#Check prime
check:
bgt $s0,$s1,Exit
move $a0,$s0
jal checkPrime
addi $s0,$s0,1
j check
#End of the program
Exit:
bne $a1,0,end
la
$a0,noPrime
#Address of no prime msg
li
$v0,4
#Systeem call for string display
syscall
#display string
end:
li
$v0,10
#Program end system call
syscall
#end
#Negative error message
error1:
la
$a0,Error
#Address of Error message
li
$v0,4
#Systeem call for string display
syscall
#display string
j
main
#go to main
#Negative error message
error2:
la
$a0,Error
#Address of Error message
li
$v0,4
#Systeem call for string display
syscall
#display string
j
second
#go to second prompt
#Display bound error
boundError:
la
$a0,BoundCheckError
#Address of bounde error message
li
$v0,4
#Systeem call for string display
syscall
#display string
j
second
#go to second prompt
#Display primes prompt
la
$a0,result
#Address of Error message
li
$v0,4
#Systeem call for string display
syscall
#display string
#prime check function
checkPrime:
li
$t0,0
#Flag for prime check
li
$t1,2
#for loop
beq
$a0,1,print1
#compare integer=1
div
$t2,$a0,2
#n/2
#loop for prime check
loop:
bgt
$t1,$t2,print
#for(i = 2; i <= n/2; ++i)
div
$a0,$t1
#Mode finding
mfhi
$t4
#Mode value
beq
$t4,0,return
#if mode =0 no prime
addi
$t1,$t1,1
#Increment
counter
j
loop
#Repeat
print:
li
$v0,1
#If prime print value syatem call
syscall
#Print integeer
la
$a0,space
#Address of space
li
$v0,4
#System call to print string
syscall
#Print string
addi
$a1,$a1,1
#counter for prime numbers
jr
$ra
#return to main method
#If not prime return to main without display
return:
jr $ra
#If integer=1
print1:
la
$a0,OneDisplay
#Address of 1 value display
li
$v0,4
#Systeem call for string display
syscall
#display string
jr
$ra
#return to main
---------------------------------------------------
Output
Enter A: 20
Enter B: 22
Prime numbers are:
No prime number between numbers A and B
-- program is finished running --
Enter A: 10
Enter B: 20
Prime numbers are:
11 13 17 19
-- program is finished running --
Write a MIPS Assembly program to accept two numbers A and B from the user. Print...
Write a program that will accept two numbers from the user. The program will then print all the numbers from the lowest number to the highest number. Make sure to include both numbers in the count. Also, it should not matter what order you input the two numbers. c++
Write a MIPS assembly program to calculate nCr. The program should accept the numbers n and r from the user. The program should call the factorial function. nCr = n! / ((n-r)! * r!) If n<r print an error message "n should not be less than r: re-enter the values." and get the inputs n and r from the user.
Write a program in MIPS to accept a string from a user, reverse that string and print it out to the user. You must write a procedure that performs the reversal task. Example: Please Enter a String: Hello How Are You Reversed String: uoY erA woH olleH
1- Write a mips program to read two integers from the user, and print the smaller one 1- Write a mips program to read two integers from the user, and print the smaller one
Accept 2 numbers from user add them and print the sum using MARS mips
Write a simple and short MIPS assembly language program that asks the user for 6 numbers, merge-sorts them, and then prints them out in ascending order comment each and every programme .(USING WINDOWS QtSpim) Note : This question is not giving desired solution may you please try it in a simple manner for six number inputed by the user.
Please I need the correct and comment of code in MIPS assembly program to Receive a positive integer number from the user and print out “prime”/“not prime” result if the entered number is prime or not.
Using Matlab Write a program which will: a. Accept two numbers from the user m and n b. Define an array with the dimensions a(n,m) and fill it with random numbers in the range of -100 to 100 inclusive. c. Provide the user the following menu from which he can select: 1. Sum of all elements in the array. Print the result. 2. Sum of the element in a row that he’ll specify. Print the result. 3. Sum of the...
2. Searching a String: Write a MIPS assembly language program to do the following: Read a string and store it in memory. Limit the string length to 100 characters. Then, ask the user to enter a character. Search and count the number of occurrences of the character in the string. The search is not case sensitive. Lowercase and uppercase letters should be equal. Then ask the user to enter a string of two characters. Search and count the number of...
1. Write a program in Assembly language using MIPS instruction set that reads two integer numbers from the user named as start and end number and finds out all the prime numbers between start and end (including start and end). Your program should do the validation of both the numbers as follows: i. start number must be smaller or equal to the end number. ii. Both numbers must be positive. iii. The maximum value for the end number is 10000...