Lab4

.pdf

School

CUNY College of Staten Island *

*We aren’t endorsed by this school

Course

CSC-220

Subject

Computer Science

Date

Dec 6, 2023

Type

pdf

Pages

3

Uploaded by JudgeRain11219 on coursehero.com

1 Lab-4 Loops, Pointers and Stack Frame Given the following ARM64 assembly xor.s, copy it into Raspberry Pi, then use “gcc –g –o xor xor.s” to compile it. You should see a generated executable file “xor” in the directory. .text .global main main: sub sp, sp, #48 str wzr, [sp, 44 ] mov x0, 0x1718 movk x0, 0x1516 , lsl 16 movk x0, 0x1314 , lsl 32 movk x0, 0x1112 , lsl 48 str x0, [sp, 8 ] mov x0, 0x6789 movk x0, 0x2345 , lsl 16 movk x0, 0xef01 , lsl 32 movk x0, 0xabcd , lsl 48 str x0, [sp] add x0, sp, 8 str x0, [sp, 32 ] mov x0, sp str x0, [sp, 24 ] loop: ldr w0, [sp, 44 ] cmp w0, 7 bgt exit ldr x0, [sp, 32 ] ldrb w0, [x0] strb w0, [sp, 23 ] ldr x0, [sp, 24 ] ldrb w0, [x0] strb w0, [sp, 22 ] ldrb w1, [sp, 23 ] ldrb w0, [sp, 22 ] eor w0, w1, w0 strb w0, [sp, 23 ] ldr x0, [sp, 32 ] ldrb w1, [sp, 23 ] strb w1, [x0] ldr x0, [sp, 32 ] add x0, x0, 1 str x0, [sp, 32 ] ldr x0, [sp, 24 ] add x0, x0, 1 str x0, [sp, 24 ] ldr w0, [sp, 44 ] add w0, w0, 1 str w0, [sp, 44 ] b loop exit: mov w0, 0 add sp, sp, 48 ret
2 Open a terminal window, single step run the program in the debugger GDB by “gdb ./xor” to figure out what it does. Answer these questions: 1. Add commends to each line of code to tell what they do. 2. What does the initial main stack frame look like right after executing line-5: sub sp, sp, #48 ? 3. What are the values stored in the main stack frame before entering the loop ? Fill the following stack frame table. SP +8 +16 +24 +32 +40 4. What are the values stored in the main stack frame after the first iteration of the loop ? Fill the following stack frame table. SP +8 +16 +24 +32 +40 5. What are the values stored in the main stack frame after the second iteration of the loop ? Fill the following stack frame table. SP +8 +16 +24 +32 +40 6. What are the values stored in the main stack frame after the loop ? Fill the following stack frame table. SP +8 +16 +24 +32 +40
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help