From ab03d3be21f229be8c28dba292d5da237a929a73 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 28 Aug 2024 22:25:56 +0200 Subject: Restructure the whole thing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It will be something more than just messing around with RISC-V stuff. Signed-off-by: Miquel Sabaté Solà --- basics/factorial.S | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 basics/factorial.S (limited to 'basics/factorial.S') diff --git a/basics/factorial.S b/basics/factorial.S deleted file mode 100644 index 7e3df12..0000000 --- a/basics/factorial.S +++ /dev/null @@ -1,28 +0,0 @@ -.text -.globl factorial -.type factorial, @function - -factorial: - // If input <= 1, just return the given thing. - addi t0, zero, 1 - bgt a0, t0, else - jr ra -else: - // Preserve the argument and the return address before the call. - addi sp, sp, -16 - sd a0, 0(sp) - sd ra, 8(sp) - - // Call the same function but with a value of argument-1. - addi a0, a0, -1 - call factorial - - // Restore back the original argument and the return address. Then multiply - // the original argument with the returned one from the previous call. - ld t1, 0(sp) - ld ra, 8(sp) - addi sp, sp, 16 - mul a0, t1, a0 - - // And return to the caller. - jr ra -- cgit v1.2.3