Page 165 - ARM 64 Bit Assembly Language
P. 165
Structured programming 151
4 stp x29, x30, [sp, #-16]!
.
5 . .
6 // function statements
.
7 . .
8 ldp x29, x30, [sp], #16
9 ret
5.6. Convert the following C program to AArch64 assembly, using a post-test loop:
1 int main()
2 {
3 for(i = 0; i < 10; i++)
4 printf("Hi!\n");
5 return 0;
6 }
5.7. Write a complete AArch64 function to shift a 128 bit value left by any amount be-
tween 0 and 127 bits. The function should expect its arguments to be in registers x0,
x1,and w2. The lower 64 bits of the value are passed in x0, the upper 64 bits of the
value are passed in x1, and the shift amount is passed in w2.
5.8. Write a complete subroutine in AArch64 assembly that is equivalent to the following C
subroutine.
1 /* This function copies ’count’ bytes from ’src’ to ’dest’. */
2 void bytecopy(char dest[], char src[], int count)
3 {
4 count = count - 1;
5 while(count >= 0)
6 {
7 dest[count] = src[count];
8 count = count - 1;
9 }
10 }
5.9. Write a complete function in AArch64 assembly that is equivalent to the following C
function.
1 /* This function returns the minimum of six values. */
2 int minsix(int a, int b, int c, int d, int e, int f)
3 {
4 if(b < a)
5 a=b;
6 if(d < c)
7 c=d;
8 if(c < a)
9 a=c;
10 if(f < e)
11 e=f;