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]...
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...
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 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.
Write a function ‘sort1’ that takes in an array of non-zero positive integers as input and...
Write a function ‘sort1’ that takes in an array of non-zero positive integers as input and returns a second vector that contains only the odd numbers. It will return zero if all elements are even. Use error-traps to check against probable errors in user input. In case of an error, it will return NaN. You are allowed to use Matlab built-in function round(). Check your code with the following arrays: >> y1 = [18, -5, 89, -7, 4, 10, 12,...
python exercise: a. Write a function sumDigits that takes a positive integer value and returns the...
python exercise: a. Write a function sumDigits that takes a positive integer value and returns the total sum of the digits in the integers from 1 to that number inclusive. b. Write a program to input an integer n and call the above function in part a if n is positive, else give ‘Value must be Positive’ message. sample: Enter a positive integer: 1000000 The sum of the digits in the number from 1 to 1000000 is 27000001 Enter a...
Let τ (n) denote the number of positive divisors of n and σ(n) denote the sum...
Let τ (n) denote the number of positive divisors of n and σ(n) denote the sum of the positive divisors of n (as in the notes). (a) Evaluate τ (1500) and σ(8!). (b) Verify that τ (n) = τ (n + 1) = τ (n + 2) = τ (n + 3) holds for n = 3655 and 4503. (c) When n = 14, n = 206 and n = 957, show that σ(n) = σ(n + 1).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT