diff options
| -rw-r--r-- | aarch64/kusswurm_ch11.S | 65 | ||||
| -rw-r--r-- | aarch64/kusswurm_ch11.c | 26 | ||||
| -rw-r--r-- | aarch64/meson.build | 1 |
3 files changed, 92 insertions, 0 deletions
diff --git a/aarch64/kusswurm_ch11.S b/aarch64/kusswurm_ch11.S new file mode 100644 index 0000000..0407e92 --- /dev/null +++ b/aarch64/kusswurm_ch11.S @@ -0,0 +1,65 @@ +// ================================================================================================ +// 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 "common.S" + +TEXT_SEGMENT + +// example 1 + +.global SYM(i32_add_sub) +.global SYM(i64_add_sub) + +SYM(i32_add_sub): + // w0: a + // w1: b + // w2: c +#if 0 + add w3, w0, w1 + sub w0, w3, w2 +#else + add w0, w0, w1 + sub w0, w0, w2 +#endif + // w0: return + ret + +SYM(i64_add_sub): + // x0: a + // x1: b + // x2: c + add x3, x0, x1 + sub x0, x3, x2 + // x0: return + ret + +// example 2 + +.global SYM(i32_mul) +.global SYM(i32_mul_safe) + +SYM(i32_mul): + // w0: a + // w1: b + mul w0, w0, w1 + // w0: return + ret + +SYM(i32_mul_safe): + // w0: a + // w1: b + smull x0, w0, w1 + // x0: ret + ret + diff --git a/aarch64/kusswurm_ch11.c b/aarch64/kusswurm_ch11.c new file mode 100644 index 0000000..4edfba0 --- /dev/null +++ b/aarch64/kusswurm_ch11.c @@ -0,0 +1,26 @@ +#include <stdint.h> +#include <stdio.h> + +// example 1 +int32_t i32_add_sub(int32_t a, int32_t b, int32_t c); +int64_t i64_add_sub(int64_t a, int64_t b, int64_t c); + +// example 2 +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) + +int main(int argc, const char* argv[]) +{ + // example 1 + PRINT_LOG("%d", i32_add_sub(5, 3, 1)); + PRINT_LOG("%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)); +} + diff --git a/aarch64/meson.build b/aarch64/meson.build index aea3a3f..c664858 100644 --- a/aarch64/meson.build +++ b/aarch64/meson.build @@ -1,4 +1,5 @@ project('aarch64', 'c') +executable('kusswurm_ch11', [ 'kusswurm_ch11.c', 'kusswurm_ch11.S' ]) executable('mariokartwii_ch07', 'mariokartwii_ch07.S') executable('mariokartwii_ch08', 'mariokartwii_ch08.S') |