change this C code to Assembly program(x86 and ARM assembly gcc)   #include int main() { unsigned guess; /* current guess for prime */ unsigned factor; /* possible factor of guess */ unsigned limit; /* find primes up to this value */   printf("Find primes up to: "); scanf("%u", &limit);   printf("2\n"); /* treat first two primes as special case */ printf("3\n");   guess = 5; /* initial guess */ while ( guess <= limit ) { /* look for a factor of guess */ factor = 3; while ( factor*factor < guess && guess % factor != 0 ) factor += 2; if ( guess % factor != 0 ) printf("%d\n", guess); guess += 2; /* only look at odd numbers */ } printf("Recieves a number(limit) and prints its all divisors");  for(int i = 1; i <= limit; i++) {   if((limit%i) == 0){    printf("\n%d", i);       }  } return 0; }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please change this C code to Assembly program(x86 and ARM assembly gcc)

 

#include <stdio.h>
int main()

{

unsigned guess; /* current guess for prime */

unsigned factor; /* possible factor of guess */

unsigned limit; /* find primes up to this value */

 

printf("Find primes up to: ");

scanf("%u", &limit);

 

printf("2\n"); /* treat first two primes as special case */

printf("3\n");

 

guess = 5; /* initial guess */

while ( guess <= limit ) {

/* look for a factor of guess */

factor = 3;

while ( factor*factor < guess && guess % factor != 0 )

factor += 2;
if ( guess % factor != 0 )

printf("%d\n", guess);

guess += 2; /* only look at odd numbers */

}
printf("Recieves a number(limit) and prints its all divisors");
 for(int i = 1; i <= limit; i++) {
  if((limit%i) == 0){
   printf("\n%d", i);
   
  }
 }

return 0;

}

Expert Solution
Step 1 : x86
.LC0:
        .string "Find primes up to: "
.LC1:
        .string "%u"
.LC2:
        .string "2"
.LC3:
        .string "3"
.LC4:
        .string "%d\n"
.LC5:
        .string "Recieves a number(limit) and prints its all divisors"
.LC6:
        .string "\n%d"
main:
        push    %rbp
        push    %rbx
        sub     %rsp, 24
        mov     %edi, OFFSET FLAT:.LC0
        mov     %eax, 0
        call    printf
        lea     %rsi, [%rsp+20]
        mov     %edi, OFFSET FLAT:.LC1
        mov     %eax, 0
        call    scanf
        mov     %edi, OFFSET FLAT:.LC2
        call    puts
        mov     %edi, OFFSET FLAT:.LC3
        call    puts
        mov     %ebx, 5
        mov     %ebp, -1431655765
        cmp     DWORD PTR [%rsp+20], 4
        ja      .L4
        jmp     .L2
.L6:
        add     %ecx, 2
        mov     %eax, %ecx
        imul    %eax, %ecx
        cmp     %eax, %ebx
        jae     .L7
        mov     %eax, %ebx
        mov     %edx, 0
        div     %ecx
        test    %edx, %edx
        je      .L9
        jmp     .L6
.L10:
        mov     %ecx, 3
.L7:
        mov     %eax, %ebx
        mov     %edx, 0
        div     %ecx
        test    %edx, %edx
        je      .L9
        mov     %esi, %ebx
        mov     %edi, OFFSET FLAT:.LC4
        mov     %eax, 0
        call    printf
.L9:
        add     %ebx, 2
        cmp     DWORD PTR [%rsp+20], %ebx
        jb      .L2
.L4:
        cmp     %ebx, 9
        jbe     .L10
        mov     %eax, %ebx
        mul     %ebp
        shr     %edx
        lea     %edx, [%rdx+%rdx*2]
        mov     %ecx, 3
        cmp     %ebx, %edx
        jne     .L6
        jmp     .L9
.L2:
        mov     %edi, OFFSET FLAT:.LC5
        mov     %eax, 0
        call    printf
        mov     %ebx, 1
        cmp     DWORD PTR [%rsp+20], 0
        jne     .L15
        jmp     .L13
.L16:
        mov     %ecx, %edx
        mov     %edx, 0
        div     %ecx
        test    %edx, %edx
        jne     .L17
.L15:
        mov     %esi, %ebx
        mov     %edi, OFFSET FLAT:.LC6
        mov     %eax, 0
        call    printf
.L17:
        inc     %ebx
        mov     %edx, %ebx
        mov     %eax, DWORD PTR [%rsp+20]
        cmp     %ebx, %eax
        jbe     .L16
.L13:
        mov     %eax, 0
        add     %rsp, 24
        pop     %rbx
        pop     %rbp
        ret
 
NOTE : is a program of x86-64 4.1.2 
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY