Here is my Aarch64 assembly language program. Modify code in loop2 so it prints elements…
- User
Here is my Aarch64 assembly language program. Modify code in loop2 so it prints elements of array using printf. .section .data array: .skip 40 // reserve space for 10 integers i: .word 5 fmtstr: .string "%d\n"
.section .bssrnum: .skip 4
.section .text .global main .type main, @functionmain: mov x1, 0 // initialize loop counter to 0 mov x2, 10 // set loop limit to 10
loop1: cmp x1, x2 // compare loop counter to loop limit beq endloop1 // if equal, exit loop ldr x3, =array // load address of array str w1, [x3, x1, lsl #2] // store int 1 at index x0 of array add x1, x1, 1 // increment loop counter b loop1 // jump to start of loop
endloop1: mov x1, 0 // initialize loop counter to 0
loop2: cmp x1, x2 beq endloop2
add x1, x1, 1 // increment loop counter b loop2 // jump to start of loop2endloop2: ret // return from main function
- Assistant
To print the elements of the array using printf, you need to load the address of the fmtstr string and call the printf function. Here's the modified code for loop2:
.section .data array: .skip 40 // reserve space for 10 integers i: .word 5 fmtstr: .string "%d\n" .section .bss rnum: .skip 4 .section .text .global main .type main, @function main: mov x1, 0 // initialize loop counter to 0 mov x2, 10 // set loop limit to 10 loop1: cmp x1, x2 // compare loop counter to loop limit beq endloop1 // if equal, exit loop ldr x3, =array // load address of array str w1, [x3, x1, lsl #2] // store int 1 at index x0 of array add x1, x1, 1 // increment loop counter b loop1 // jump to start of loop endloop1: mov x1, 0 // initialize loop counter to 0 loop2: cmp x1, x2 beq endloop2 ldr x3, =array // load address of array ldr w0, [x3, x1, lsl #2] // load array element at index x1 to w0 ldr x3, =fmtstr // load address of fmtstr mov x1, x3 // move the address of fmtstr to x1 bl printf // call printf function add x1, x0, 1 // increment loop counter b loop2 // jump to start of loop2 endloop2: ret // return from main function