Question

In: Computer Science

Write a function DIVISORS in MIPS. This function takes a positive number from the register a0...

Write a function DIVISORS in MIPS. This function takes a positive number from the register a0 and prints in a column all of its divisors including 1 and the number itself. Don't forget that printing a number and printing a character requires two different system calls.

Here is an example. If the number in a0 is 6 the following output appears:

1

2

3

6

Solutions

Expert Solution

solution:

given data:

code:
.text
main:
li $v0, 5 #this is the system call for reading an integer
syscall #the value will be read in $v0
move $s0, $v0 #set $s0=n
li $s1, 1 #this is the iterator variable, for iterating 1 to n
while:
div $s0, $s1 #the remainder will be in HI
mfhi $s2 #load the remainder into $s2
bne $s2, $0, incr #don't print the number if remainder is not 0
move $a0, $s1 #the number is divisor, so print it
li $v0, 1
syscall
li $v0, 11 #print a newline
li $a0, 10
syscall
incr:
addi $s1, $s1, 1
bge $s0, $s1, while
li $v0, 10 #this exits the code
syscall

Here is a screenshot of the code:

here is a screenshot of some outputs (note that the first line is the input I gave):

please give me thumb up


Related Solutions

Write a function fun(x) that takes as input a positive number x and solves the following...
Write a function fun(x) that takes as input a positive number x and solves the following equation for y and returns y. The equation is 10^4y=x+3. Could you help me with this by using python? I can use loop or if statement for this question.
Match a student number: Write a function MatchStudentNumber that takes a student number from the StudentNumber...
Match a student number: Write a function MatchStudentNumber that takes a student number from the StudentNumber column in the reference table and determine if there is a match with a student number from the StudentNumber column in the second table. The output is a logical flag that is true if at least one match was found, and integer array that points to rows in table where a match occurred. Note that the function should find all matches. function [iflag, matchPosition]...
Use the Multiplication Rule to find the number of positive divisors of 20!. Include a procedure...
Use the Multiplication Rule to find the number of positive divisors of 20!. Include a procedure that “builds” such divisors
Write a function printTwoLargest() that inputs an arbitrary number of positive numbers from the user. The...
Write a function printTwoLargest() that inputs an arbitrary number of positive numbers from the user. The input of numbers stops when the first negative or zero value is entered by the user. The function then prints the two largest values entered by the user. If no positive numbers are entered a message to that effect is printed instead of printing any numbers. If only one number is inputted, only the largest is printed out (see 2nd example below). Sample output:...
Write a program in MIPS assembly language to convert an ASCII number string containing positive and...
Write a program in MIPS assembly language to convert an ASCII number string containing positive and negative integer decimal strings, to an integer. Your program should expect register $a0 to hold the address of a nullterminated string containing some combination of the digits 0 through 9. Your program should compute the integer value equivalent to this string of digits, then place the number in register $v0. If a non-digit character appears anywhere in the string, your program should stop with...
Write a function that takes a number as input, and returns the character A if the...
Write a function that takes a number as input, and returns the character A if the input is 90 and above, B if it’s 80 and above but less than 90, C if it’s at least 70 but less than 80, D if it’s at least 60 but less than 70, and F if it’s less than 60. If the input is not a number or is negative, the function should exit 1 with an error (by calling the Matlab...
PYTHON: Write a function insertInOrder that takes in a list and a number. This function should...
PYTHON: Write a function insertInOrder that takes in a list and a number. This function should assume that the list is already in ascending order. The function should insert the number into the correct position of the list so that the list stays in ascending order. It should modify the list, not build a new list. It does not need to return the list, because it is modifying it.   Hint: Use a whlie loop and list methods lst = [1,3,5,7]...
In R studio Write a function that takes as an input a positive integer and uses...
In R studio Write a function that takes as an input a positive integer and uses the print() function to print out all the numbers less than the input integer. (Example: for input 5, the function should print the numbers 1,2,3,4 { for input 1, the function should not print a number.) Use the lapply function, do not use any of the loop commands in your code.
C++ 1. Write a function decimalToBinary() that takes in a positive integer as a parameter and...
C++ 1. Write a function decimalToBinary() that takes in a positive integer as a parameter and use as stack to convert the integer to a its corresponding binary representation. Hint: divide the integer by 2. 2. A palindrome is a string of characters (a word, phrase, or sentence) that is the same regardless of whether you read it forward or backward—assuming that you ignore spaces, punctuation, and case. For example, Race car is a palindrome. So is A man, a...
Write a MIPS Assembly program function to calculate the factorial of an input number. Analyze the...
Write a MIPS Assembly program function to calculate the factorial of an input number. Analyze the program for the value 10 and compute the Execution time in a MIPS processor at 2.4GHz. The CPI is 1.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT