Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an ARMv7 assembly code that is translated from the following C program #in

ID: 3831693 • Letter: W

Question

Write an ARMv7 assembly code that is translated from the following C program

#include<stdio.h>

int main(){
   int n;
   int max;
   int min;
   int test;
   int i;

   printf("Please input 'n' number of integers that you would like to compare ");
   scanf("%d",&n);

   if(n<=0){
       printf("Please input a non zero positive integer ");
       return 0;
   }

   printf("Please input each number ");
   scanf("%d",&test);

   max=test;
   min=test;

   for(i=1;i<n;i++){
       scanf("%d",&test);

       if(max < test)
       {
           max=test;
       }
       else if(min > test){
           min=test;
       }      
   }

   printf("The Max number is %d ",max);
   printf("The Min number is %d ",min);

   return 0;
}

Explanation / Answer

.LC0:
.string "Please input 'n' number of integers that you would like to compare"
.LC1:
.string "%d"
.LC2:
.string "Please input a non zero positive integer"
.LC3:
.string "Please input each number"
.LC4:
.string "The Max number is %d "
.LC5:
.string "The Min number is %d "
main:
push rbp
mov rbp, rsp
sub rsp, 32
mov edi, OFFSET FLAT:.LC0
call puts
lea rax, [rbp-16]
mov rsi, rax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call scanf
mov eax, DWORD PTR [rbp-16]
test eax, eax
jg .L2
mov edi, OFFSET FLAT:.LC2
call puts
mov eax, 0
jmp .L8
.L2:
mov edi, OFFSET FLAT:.LC3
call puts
lea rax, [rbp-20]
mov rsi, rax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call scanf
mov eax, DWORD PTR [rbp-20]
mov DWORD PTR [rbp-4], eax
mov eax, DWORD PTR [rbp-20]
mov DWORD PTR [rbp-8], eax
mov DWORD PTR [rbp-12], 1
.L7:
mov eax, DWORD PTR [rbp-16]
cmp DWORD PTR [rbp-12], eax
jge .L4
lea rax, [rbp-20]
mov rsi, rax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call scanf
mov eax, DWORD PTR [rbp-20]
cmp DWORD PTR [rbp-4], eax
jge .L5
mov eax, DWORD PTR [rbp-20]
mov DWORD PTR [rbp-4], eax
jmp .L6
.L5:
mov eax, DWORD PTR [rbp-20]
cmp DWORD PTR [rbp-8], eax
jle .L6
mov eax, DWORD PTR [rbp-20]
mov DWORD PTR [rbp-8], eax
.L6:
add DWORD PTR [rbp-12], 1
jmp .L7
.L4:
mov eax, DWORD PTR [rbp-4]
mov esi, eax
mov edi, OFFSET FLAT:.LC4
mov eax, 0
call printf
mov eax, DWORD PTR [rbp-8]
mov esi, eax
mov edi, OFFSET FLAT:.LC5
mov eax, 0
call printf
mov eax, 0
.L8:
leave
ret

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote