From 96ecfa9adf39a9b87de74d4ed5c083c461296065 Mon Sep 17 00:00:00 2001 From: Maxime Vorwerk Date: Tue, 11 Jun 2024 16:14:44 +0200 Subject: [PATCH] ARMssembly 3 --- ARMssembly_3/chall_3.S | 72 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 ARMssembly_3/chall_3.S diff --git a/ARMssembly_3/chall_3.S b/ARMssembly_3/chall_3.S new file mode 100755 index 0000000..e39a6e6 --- /dev/null +++ b/ARMssembly_3/chall_3.S @@ -0,0 +1,72 @@ + .arch armv8-a + .file "chall_3.c" + .text + .align 2 + .global func1 + .type func1, %function +func1: + stp x29, x30, [sp, -48]! + add x29, sp, 0 + str w0, [x29, 28] + str wzr, [x29, 44] + b .L2 +.L4: + ldr w0, [x29, 28] + and w0, w0, 1 + cmp w0, 0 + beq .L3 + ldr w0, [x29, 44] + bl func2 + str w0, [x29, 44] +.L3: + ldr w0, [x29, 28] + lsr w0, w0, 1 + str w0, [x29, 28] +.L2: + ldr w0, [x29, 28] + cmp w0, 0 + bne .L4 + ldr w0, [x29, 44] + ldp x29, x30, [sp], 48 + ret + .size func1, .-func1 + .align 2 + .global func2 + .type func2, %function +func2: + sub sp, sp, #16 + str w0, [sp, 12] + ldr w0, [sp, 12] + add w0, w0, 3 + add sp, sp, 16 + ret + .size func2, .-func2 + .section .rodata + .align 3 +.LC0: + .string "Result: %ld\n" + .text + .align 2 + .global main + .type main, %function +main: + stp x29, x30, [sp, -48]! + add x29, sp, 0 + str w0, [x29, 28] + str x1, [x29, 16] + ldr x0, [x29, 16] + add x0, x0, 8 + ldr x0, [x0] + bl atoi + bl func1 + str w0, [x29, 44] + adrp x0, .LC0 + add x0, x0, :lo12:.LC0 + ldr w1, [x29, 44] + bl printf + nop + ldp x29, x30, [sp], 48 + ret + .size main, .-main + .ident "GCC: (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 7.5.0" + .section .note.GNU-stack,"",@progbits