Advertisement
robjones90

Untitled

May 31st, 2023
962
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.03 KB | None | 0 0
  1. //C code
  2.  
  3. #include <stdio.h>
  4. int main() {
  5.   int n;
  6.   double arr[100];
  7.   printf("Enter the number of elements (1 to 100): ");
  8.   scanf("%d", &n);
  9.  
  10.   for (int i = 0; i < n; ++i) {
  11.     printf("Enter number%d: ", i + 1);
  12.     scanf("%lf", &arr[i]);
  13.   }
  14.  
  15.   // storing the largest number to arr[0]
  16.   for (int i = 1; i < n; ++i) {
  17.     if (arr[0] < arr[i]) {
  18.       arr[0] = arr[i];
  19.     }
  20.   }
  21.  
  22.   printf("Largest element = %.2lf", arr[0]);
  23.  
  24.   return 0;
  25. }
  26.  
  27. ---- Apple Silicon ARM Assembly
  28.  
  29.     .section    __TEXT,__text,regular,pure_instructions
  30.     .build_version macos, 13, 0 sdk_version 13, 3
  31.     .globl  _main                           ; -- Begin function main
  32.     .p2align    2
  33. _main:                                  ; @main
  34.     .cfi_startproc
  35. ; %bb.0:
  36.     stp x28, x27, [sp, #-32]!           ; 16-byte Folded Spill
  37.     .cfi_def_cfa_offset 32
  38.     stp x29, x30, [sp, #16]             ; 16-byte Folded Spill
  39.     add x29, sp, #16
  40.     .cfi_def_cfa w29, 16
  41.     .cfi_offset w30, -8
  42.     .cfi_offset w29, -16
  43.     .cfi_offset w27, -24
  44.     .cfi_offset w28, -32
  45.     sub sp, sp, #832
  46.     adrp    x8, ___stack_chk_guard@GOTPAGE
  47.     ldr x8, [x8, ___stack_chk_guard@GOTPAGEOFF]
  48.     ldr x8, [x8]
  49.     stur    x8, [x29, #-24]
  50.     str wzr, [sp, #20]
  51.     adrp    x0, l_.str@PAGE
  52.     add x0, x0, l_.str@PAGEOFF
  53.     bl  _printf
  54.     mov x9, sp
  55.     add x8, sp, #16
  56.     str x8, [x9]
  57.     adrp    x0, l_.str.1@PAGE
  58.     add x0, x0, l_.str.1@PAGEOFF
  59.     bl  _scanf
  60.     str wzr, [sp, #12]
  61.     b   LBB0_1
  62. LBB0_1:                                 ; =>This Inner Loop Header: Depth=1
  63.     ldr w8, [sp, #12]
  64.     ldr w9, [sp, #16]
  65.     subs    w8, w8, w9
  66.     cset    w8, ge
  67.     tbnz    w8, #0, LBB0_4
  68.     b   LBB0_2
  69. LBB0_2:                                 ;   in Loop: Header=BB0_1 Depth=1
  70.     ldr w8, [sp, #12]
  71.     add w10, w8, #1
  72.     mov x9, sp
  73.                                         ; implicit-def: $x8
  74.     mov x8, x10
  75.     str x8, [x9]
  76.     adrp    x0, l_.str.2@PAGE
  77.     add x0, x0, l_.str.2@PAGEOFF
  78.     bl  _printf
  79.     ldrsw   x9, [sp, #12]
  80.     add x8, sp, #24
  81.     add x8, x8, x9, lsl #3
  82.     mov x9, sp
  83.     str x8, [x9]
  84.     adrp    x0, l_.str.3@PAGE
  85.     add x0, x0, l_.str.3@PAGEOFF
  86.     bl  _scanf
  87.     b   LBB0_3
  88. LBB0_3:                                 ;   in Loop: Header=BB0_1 Depth=1
  89.     ldr w8, [sp, #12]
  90.     add w8, w8, #1
  91.     str w8, [sp, #12]
  92.     b   LBB0_1
  93. LBB0_4:
  94.     mov w8, #1
  95.     str w8, [sp, #8]
  96.     b   LBB0_5
  97. LBB0_5:                                 ; =>This Inner Loop Header: Depth=1
  98.     ldr w8, [sp, #8]
  99.     ldr w9, [sp, #16]
  100.     subs    w8, w8, w9
  101.     cset    w8, ge
  102.     tbnz    w8, #0, LBB0_10
  103.     b   LBB0_6
  104. LBB0_6:                                 ;   in Loop: Header=BB0_5 Depth=1
  105.     add x8, sp, #24
  106.     ldr d0, [sp, #24]
  107.     ldrsw   x9, [sp, #8]
  108.     ldr d1, [x8, x9, lsl #3]
  109.     fcmp    d0, d1
  110.     cset    w8, pl
  111.     tbnz    w8, #0, LBB0_8
  112.     b   LBB0_7
  113. LBB0_7:                                 ;   in Loop: Header=BB0_5 Depth=1
  114.     ldrsw   x9, [sp, #8]
  115.     add x8, sp, #24
  116.     ldr d0, [x8, x9, lsl #3]
  117.     str d0, [sp, #24]
  118.     b   LBB0_8
  119. LBB0_8:                                 ;   in Loop: Header=BB0_5 Depth=1
  120.     b   LBB0_9
  121. LBB0_9:                                 ;   in Loop: Header=BB0_5 Depth=1
  122.     ldr w8, [sp, #8]
  123.     add w8, w8, #1
  124.     str w8, [sp, #8]
  125.     b   LBB0_5
  126. LBB0_10:
  127.     ldr d0, [sp, #24]
  128.     mov x8, sp
  129.     str d0, [x8]
  130.     adrp    x0, l_.str.4@PAGE
  131.     add x0, x0, l_.str.4@PAGEOFF
  132.     bl  _printf
  133.     ldur    x9, [x29, #-24]
  134.     adrp    x8, ___stack_chk_guard@GOTPAGE
  135.     ldr x8, [x8, ___stack_chk_guard@GOTPAGEOFF]
  136.     ldr x8, [x8]
  137.     subs    x8, x8, x9
  138.     cset    w8, eq
  139.     tbnz    w8, #0, LBB0_12
  140.     b   LBB0_11
  141. LBB0_11:
  142.     bl  ___stack_chk_fail
  143. LBB0_12:
  144.     mov w0, #0
  145.     add sp, sp, #832
  146.     ldp x29, x30, [sp, #16]             ; 16-byte Folded Reload
  147.     ldp x28, x27, [sp], #32             ; 16-byte Folded Reload
  148.     ret
  149.     .cfi_endproc
  150.                                         ; -- End function
  151.     .section    __TEXT,__cstring,cstring_literals
  152. l_.str:                                 ; @.str
  153.     .asciz  "Enter the number of elements (1 to 100): "
  154.  
  155. l_.str.1:                               ; @.str.1
  156.     .asciz  "%d"
  157.  
  158. l_.str.2:                               ; @.str.2
  159.     .asciz  "Enter number%d: "
  160.  
  161. l_.str.3:                               ; @.str.3
  162.     .asciz  "%lf"
  163.  
  164. l_.str.4:                               ; @.str.4
  165.     .asciz  "Largest element = %.2lf"
  166.  
  167. .subsections_via_symbols
  168.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement