Write a MIPS assembly language program that repeatedly prompts the user for a ZI
ID: 3588089 • Letter: W
Question
Write a MIPS assembly language program that repeatedly prompts the user for a ZIP code, calculates the sum of all digits then prints out the result. If the input is 0 then the program stops. The sum calculation part must be written in 2 versions: recursive and non-recursive and the results are stored in two memory locations A and B, respectively. The output should be something that shows both calculations:
The sum of all digits using the recursive function is xxxxxx, using the non-recursive function is yyyyy. xxxxxx is taken from memory location A and yyyyy is from memory location B. Obviously, both numbers must be the same.
Explanation / Answer
#include //Always use meaningful names for types typedef unsigned char boolean; #define True 't' #define FALSE (!True) //this is a really neat trick for swapping values efficiently void swap(long* a,long *b) { *a=*a^*b;*b=*b^*a;*a=*a^*b; } //Here's a readability improvement #define until(condition) while(!(condition)) int main(int n, char*args[]){ double *d; int i; char input[5]; //should be long enough for most doubles. boolean sorted = FALSE; //In C, you need to specify the array size beforehand, so ask printf("Please enter the length of the array "); gets(input); //scan the input string and convert to a value sscanf(input,"%s",&input[0]); n=(long)atol(input); //allocate space, make sure you get the order of arguments right. d = calloc(sizeof(double),n); //Get and sort the array until (sorted) { for (i=0;iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.