Question: ASSEMBLY SUBROUTINE 1. Create a subroutine that will divide a value by 10. The subroutine should utilize appropriate registers for passing parameters, returning results, and
ASSEMBLY SUBROUTINE
1. Create a subroutine that will divide a value by 10. The subroutine should utilize appropriate registers for passing parameters, returning results, and only affect temporaries. Write a main program that reads a 16-bit unsigned value from SWITCHES (address 0x11000000) and converts the value into a 5 digit, BCD (binary coded decimal) value using the divide by 10 subroutine. For example, if the input value is 0x3A6C (14956 decimal), it should be split into 5 byte values for 1, 4, 9, 5, and 6, so the final answer would be 0x14956. The resulting 20-bit BCD can be written as a 32-bit word to the 7 SEGMENT (address 0x11000040).
2. Create a subroutine that implements the following greatest common denominator function given below. The subroutine should utilize appropriate registers for passing parameters, returning results, and only affect temporaries. Write a main program that reads two 16-bit unsigned values consecutively from SWITCHES (address 0x11000000) and uses the subroutine to find the GCD and outputs it to LEDS (address 0x11000020). Do not replace the subroutine with a loop. You can assume both inputs are unsigned values greater than 1. Specify any limits of your program.
| int gcd(int x, int y){ if (x == y) return x; else if (x > y) return gcd(x-y,y); else return gcd(x,y-x); } |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
