summaryrefslogtreecommitdiff
path: root/aarch64/kusswurm_ch11.c
diff options
context:
space:
mode:
Diffstat (limited to 'aarch64/kusswurm_ch11.c')
-rw-r--r--aarch64/kusswurm_ch11.c61
1 files changed, 54 insertions, 7 deletions
diff --git a/aarch64/kusswurm_ch11.c b/aarch64/kusswurm_ch11.c
index 4edfba0..58ca79f 100644
--- a/aarch64/kusswurm_ch11.c
+++ b/aarch64/kusswurm_ch11.c
@@ -1,3 +1,17 @@
+// ================================================================================================
+// Code written while reading chapter 11 of Modern Arm Assembly Language Programming
+//
+// License:
+// SPDX-License-Identifier: 0BSD
+// Copyright (c) 2026 Hunter Kvalevog
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+// WITH REGARD TO THIS SOFTWARE.
+// ================================================================================================
+
#include <stdint.h>
#include <stdio.h>
@@ -9,18 +23,51 @@ int64_t i64_add_sub(int64_t a, int64_t b, int64_t c);
int32_t i32_mul(int32_t a, int32_t b);
int64_t i32_mul_safe(int32_t a, int32_t b);
-#define PRINT_LOG(FMT, CODE) printf(#CODE ": " FMT "\n", CODE)
+// example 3
+void i32_quo_rem(int32_t num, int32_t den, int32_t *quo, int32_t *rem);
+
+// example 4
+int32_t test_ldr1(int32_t i, int64_t j, int32_t *tab);
+
+// example 5
+void test_mov1(uint32_t *tab);
int main(int argc, const char* argv[])
{
+#define X(FMT, CODE) printf(#CODE ": " FMT "\n", CODE)
+
// example 1
- PRINT_LOG("%d", i32_add_sub(5, 3, 1));
- PRINT_LOG("%lld", i64_add_sub(5, 3, 1));
+ X("%d", i32_add_sub(5, 3, 1));
+ X("%lld", i64_add_sub(5, 3, 1));
// example 2
- PRINT_LOG("%d", i32_mul(5, 6));
- PRINT_LOG("%d", i32_mul(2000000000, 4));
- PRINT_LOG("%lld", i32_mul_safe(5, 6));
- PRINT_LOG("%lld", i32_mul_safe(2000000000, 4));
+ X("%d", i32_mul(5, 6));
+ X("%d", i32_mul(2000000000, 4));
+ X("%lld", i32_mul_safe(5, 6));
+ X("%lld", i32_mul_safe(2000000000, 4));
+
+#undef X
+#define X(CODE) CODE; printf(#CODE ": quo=%d rem=%d\n", quo, rem)
+
+ // example 3
+ int32_t quo = 0;
+ int32_t rem = 0;
+ X(i32_quo_rem(6, 3, &quo, &rem));
+ X(i32_quo_rem(7, 3, &quo, &rem));
+
+#undef X
+#define X(FMT, CODE) printf(#CODE ": " FMT "\n", CODE)
+
+ // example 4
+ int32_t tab[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
+ X("%d", test_ldr1(0, 0, tab));
+
+ // example 5
+ uint32_t out[3] = { 0, 0, 0 };
+ test_mov1(out);
+ printf("test_mov1(out):\n");
+ printf(" out[0] = 0x%X\n", out[0]);
+ printf(" out[1] = 0x%X\n", out[1]);
+ printf(" out[2] = 0x%X\n", out[2]);
}