This is aarch64 assembly language program. at the end of each of iteration of loop 2,…
- User
This is aarch64 assembly language program. at the end of each of iteration of loop 2, check if x19 register plus one is multiple of 5 and if it is print nlstr .section .rodata getnstr: .string "Enter a value of n: " .align 3 origstr: .string "Original array:\n" .align 3 intstr: .string "%d" .align 3 prntstr: .string "The array values are: \n" .align 3 tab10dintstr: .string "\t%10d" .align 3 nlstr: .string "\n" .align 3
.section .bss n: .skip 4 n16: .skip 4
.section .text .global main .type main, @function
main: stp x29, x30, [sp, #-16]! // main prolog
code// Generate a seed to be used by srand and set the seed for the random number generator mov x0, 0 bl time bl srand // prompt the user to enter their TCU id number ldr x0, =getnstr bl printf ldr x0, =intstr ldr x1, =n bl scanf // Check if the TCU id number is even ldr x0, =n and x0, x0, #1 cmp x0, #0 beq even mov x0, #33 ldr x1, =n str x0, [x1] b endgetnstreven: mov x0, #42 ldr x1, =n str x0, [x1]
endgetnstr: // compute next highest multiple of 16 that is bigger or equal to n adr x1, n ldr w1, [x1] sbfiz x1, x2, #2, #20 add x1, x1, #0xf and x1, x1, #0xfffffffffffffff0 adr x2, n16 str w1, [x2]
code// create the storage for “n” integers (namely orig array) on stack pointer sub sp, sp, x1 // call init_array mov x0, sp // move address of array to x0 bl init_array // print orig array ldr x0, =origstr bl printf mov x0, sp bl print_array // restore storage for “n” integers (namely orig array) on stack pointer adr x1, n16 ldr x1, [x1] add sp, sp, x1 ldp x29, x30, [sp], #16 // main epilog mov x0, #0 ret.type init_array, @function init_array: stp x29, x30, [sp, #-16]! //function prolog
codemov x19, #4 // loop counter ldr x20, =n ldr w20, [x20] mov x21, x0loop1: cmp x19, x20 bge endloop1
code// save random value to sp array bl rand and w0, w0, #255 str w0, [x21, x19, lsl 2] add x19, x19, #1 b loop1 - Assistant
// modified print_array function print_array: stp x29, x30, [sp, #-16]! //function prolog
codemov x19, #0 // loop counter ldr x20, =n ldr w20, [x20] mov x21, x0loop2: // restore x1, x2 from sp cmp x19, x20 bge endloop2
codeldr x0, =tab10dintstr ldr w1, [x21, x19, lsl 2] bl printf add x19, x19, #1 // check if x19 plus one is multiple of 5, if yes print nlstr add x22, x19, #1 mov x23, #5 sdiv x24, x22, x23 mul x25, x24, x23 cmp x25, x22 bne continue_loop2 ldr x0, =nlstr bl printfcontinue_loop2: b loop2
endloop2: ldp x29, x30, [sp], #16 //function epilog ret
- User
This is aarch64 assembly language program. at the end of each of iteration of loop 2, check if x19 register is multiple of 5 and if it is print nlstr .section .rodata getnstr: .string "Enter a value of n: " .align 3 origstr: .string “Original array:\n” .align 3 intstr: .string “%d” .align 3 prntstr: .string “The array values are: \n” .align 3 tab10dintstr: .string “\t%10d” .align 3 nlstr: .string “\n” .align 3
.section .bss n: .skip 4 n16: .skip 4
- Assistant
// modified print_array function print_array: stp x29, x30, [sp, #-16]! //function prolog
codemov x19, #0 // loop counter ldr x20, =n ldr w20, [x20] mov x21, x0loop2: // restore x1, x2 from sp cmp x19, x20 bge endloop2
codeldr x0, =tab10dintstr ldr w1, [x21, x19, lsl 2] bl printf add x19, x19, #1 // check if x19 is multiple of 5, if yes print nlstr mov x22, #5 sdiv x23, x19, x22 mul x24, x23, x22 cmp x24, x19 bne continue_loop2 ldr x0, =nlstr bl printfcontinue_loop2: b loop2
endloop2: ldp x29, x30, [sp], #16 //function epilog ret