# Q2 Translate the following Ccode snippets to ARMv8 assembl.pdf

20 Mar 2023
1 sur 1

### Q2 Translate the following Ccode snippets to ARMv8 assembl.pdf

• 1. Q2. Translate the following C-code snippets to ARMv8 assembly code in two steps. Step-1 translate C code into goto/flattened C; and Step-2 translate the resulted goto/flattened C from Step-1 to ARM64/ARMv8 assembly code. You must follow these two steps. You must add comment to each line of assembly code to explain what it does. Hint: how to translate from C to goto/flattened C, see Princeton University Spring 2020 lecture slides from this link: https://www.cs.princeton.edu/courses/archive/spring20/cos217/lectures/14_Assembly2.pdf 1) Branch and If statement. In Step-2 when you translate goto/flattened C to assembly code, you can assume that C variables a and b have been placed in registers w0 and w1, respectively. inta,b;a= 20;ifab=a+2;a=a2;>=1){} 2) Branch and If-else statement. In Step-2 when you translate goto/flattened C to assembly code, you can assume that C variables a and b have been placed in registers w0 and w1, respectively. int a,b; if (a=10 b=a3 else b=a+33) Simple while-loop: sum of all odd numbers that are less than 50 . In Step-2 when you translate goto/flattened C to assembly code, you can assume that C variables sum, n, and i have been placed in registers w0,w1, and w2 , respectively. int sum =0,n=50; int i=1; while (i<n){ sum +=1; } i+2; 4) Simple for-loop: sum of positive numbers that are less than or equal 100. In Step-2 when you translate goto/flattened C to assembly code, you can assume that C variables sum, n, and i have been placed in registers w0, w1, and w2, respectively. int sum =0,n=100; int i; for (i=1;i<=n;i++){ sum +=1;