Question

• Program the following function in assembly. Make sure to allow recursion. int fact (int n) ;this function is allowed to cal
0 0
Add a comment Improve this question Transcribed image text
Answer #1
 ;suppose DATA is being stored in A register. ;the function works in same fashion as the above specified code.   fact: DEC A ;decrementing A register  MUL A ;multipling with A register  MOV CL,A CMP CL,01 ;checking if CL == 1 if not calling the function recursively JNZ L1  
Add a comment
Know the answer?
Add Answer to:
• Program the following function in assembly. Make sure to allow recursion. int fact (int n)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Convert the following to mips assembly: int recursion (int N) { int i, j, k; if...

    Convert the following to mips assembly: int recursion (int N) { int i, j, k; if (N greater than 9) {     print "End recursion\n";     return N; } print "Recursion in "; print N; print ":"; for (k=0; k less than N; k=k+1)     print "x"; print "\n"; i = N + 7; j = N + 1; k = 13 - i; j = recursion (j); j = j - k; j = j + i; print "Recursion...

  • Why might the following method have infinite recursion? public int infiniteRecursion(int n) { if (n >...

    Why might the following method have infinite recursion? public int infiniteRecursion(int n) { if (n > 0) { return infiniteRecursion(n) - 2; } else { return 0; } } Because the base case will never be true None of these are correct, there is no infinite recursion in this method Because there is no base case Because the recursive call does not move the parameter closer to the base case

  • Develop an x86 assembly language program that properly executes an absolute value function: int abs(int value)...

    Develop an x86 assembly language program that properly executes an absolute value function: int abs(int value) If the value passed in is negative, the value has its negative sign removed If the value passed in is positive, the value is left alone Remember that the return value must be placed in the EAX register Make sure that any registers (not EAX) used by this function are placed back to their initial states prior to exiting Allow an end user to...

  • Consider the following recursive definition of a factorial function. int factorial ( int n) {   ...

    Consider the following recursive definition of a factorial function. int factorial ( int n) {    if ( n == 0 || n ==1 )    return 1;       else    return n * factorial (n-1);    } Suppose the function factorial (4) is invoke. Trace through the function call, explicitly show how the factorial function is repeatedly called and what is the value of n in each call. Also show the value returned by each call. Give an...

  • C++ Recursion Practice! 1)Multiplication #include <iostream.h> int Multiply(int M, int N) //Performs multiplication using the +...

    C++ Recursion Practice! 1)Multiplication #include <iostream.h> int Multiply(int M, int N) //Performs multiplication using the + operator. //Pre : M and N are defined and N > 0. //Post: Returns M x N { int Prod; if (N == 1)     Prod = M;                       //base case else     Prod = M + Multiply(M, N - 1); //recursive step return Prod; } 2) Reverse #include <iostream.h> void Reverse(int N) //Displays string of length N in the reverse order //Pre : N...

  • C++ Recursion Code a function which displays the first n prime numbers. The prototype is: void...

    C++ Recursion Code a function which displays the first n prime numbers. The prototype is: void prime (int) The number of primes to display is passed as the parameter. The function prime itself is not recursive. However, it should call a separate recursive helper function which determines if a given number is prime #include <iostream> using namespace std; void prime(int ) { } int main() {    prime (21);    return 0; }

  • Translate the following C program to Pep/9 assembly language. #include <stdio.h> int main() {     int...

    Translate the following C program to Pep/9 assembly language. #include <stdio.h> int main() {     int number;     scanf("%d", &number);     if (number % 2 == 0) {         printf("Even\n");     }     else {         printf("Odd\n");     }     return 0; }

  • Convert the program you wrote in to an MIPS assembly program. Make sure that you show...

    Convert the program you wrote in to an MIPS assembly program. Make sure that you show the symbol table (assume memory is allocated beginning address 5000) and that the equivalent assembly program is commented. int main() { int a[10]; int i = 0; while( i <= 5) { a[i]=i; a[9-i]=9-i; i++; }

  • Write an assembly language program that corresponds to the following C program: int width; int length;...

    Write an assembly language program that corresponds to the following C program: int width; int length; int perim; int main () { scanf ("%d%d", &width, &length); perim = (width + length) * 2; printf ("width = %d\n", width); printf ("length = %d\n\n", width); printf ("perim = %d\n", perim); return 0; }

  • #include <stdio.h>    int josephus(int n, int k) {   if (n == 1)     return 1;   else...

    #include <stdio.h>    int josephus(int n, int k) {   if (n == 1)     return 1;   else     /* The position returned by josephus(n - 1, k) is adjusted because the        recursive call josephus(n - 1, k) considers the original position         k%n + 1 as position 1 */     return (josephus(n - 1, k) + k-1) % n + 1; }    // Driver Program to test above function int main() {   int n = 14;   int k = 2;   printf("The chosen place...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT