Kat H.

asked • 05/09/21

Write the assembly code in AT&T syntax for the functions recursive, iterative, and closed, intended for people to be able to read it, not in assembly compiled and generated by a machine.

Write the assembly code in AT&T syntax for the functions recursiveiterative, and closed, intended for people to be able to read it, not in assembly compiled and generated by a machine. They are in C. Write the assembly code for the functions as separate assignments. Please provide source code and screenshots.


Function Code:

#include <inttypes.h>

#include <math.h>

uint64_t fibonacci_recursive(uint64_t n);

uint64_t fibonacci_iterative(uint64_t n);

uint64_t fibonacci_closed(uint64_t n);

double phi;

int main() {

uint64_t n;

scanf("%" SCNu64, &n);

phi = (1.0 + sqrt(5.0)) / 2.0;

printf("Recursive: %" PRIu64 "\n", fibonacci_recursive(n));

printf("Iterative: %" PRIu64 "\n", fibonacci_iterative(n));

printf("Closed: %" PRIu64 "\n", fibonacci_closed(n));

return 0;

}

uint64_t fibonacci_recursive(uint64_t n)

{

if(n == 0)

return 0;

else if (n == 1)

return 1;

return (fibonacci_recursive(n - 1) + fibonacci_recursive(n - 2));

}

uint64_t fibonacci_iterative(uint64_t n)

{

uint64_t fn = 1, fn_1 = 0;

for(int i = 2; i <= n; i++)

{

uint64_t temp = fn + fn_1;

fn_1 = fn;

fn = temp;

}

return fn;

}

uint64_t fibonacci_closed(uint64_t n)

{

return (pow(phi,n) - pow(-1,n)/pow(phi,n))/sqrt(5);

}

main.c Code:

#include <stdio.h>

#include <inttypes.h>

#include <math.h>

uint64_t fibonacci_recursive(uint64_t n);

uint64_t fibonacci_iterative(uint64_t n);

uint64_t fibonacci_closed(uint64_t n);

double phi;

int main() {

uint64_t n;

scanf("%" SCNu64, &n);

phi = (1.0 + sqrt(5.0)) / 2.0;

printf("Recursive: %" PRIu64 "\n", fibonacci_recursive(n));

printf("Iterative: %" PRIu64 "\n", fibonacci_iterative(n));

printf("Closed: %" PRIu64 "\n", fibonacci_closed(n));

return 0;

}


1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.