aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2026-02-18 09:13:46 +0100
committerFelix Morgner <felix.morgner@gmail.com>2026-02-18 09:13:46 +0100
commitdaab8f61297289697e9affe36450e12c57f2b094 (patch)
treeda73e2ee95bdf697c6df65d61ff660f3a37bb9e0
parent4165404f85bf542d5f7a42d81b7288a91a72296d (diff)
downloadsnake.s-daab8f61297289697e9affe36450e12c57f2b094.tar.xz
snake.s-daab8f61297289697e9affe36450e12c57f2b094.zip
refactor: extract error function
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/error.S20
-rw-r--r--src/main.S17
3 files changed, 21 insertions, 17 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 90d304a..2d88dcf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,6 +9,7 @@ project("snake.s"
find_package("SDL2" REQUIRED)
add_executable("snake.s"
+ "src/error.S"
"src/main.S"
)
diff --git a/src/error.S b/src/error.S
new file mode 100644
index 0000000..af441ce
--- /dev/null
+++ b/src/error.S
@@ -0,0 +1,20 @@
+#include "helpers/function.S"
+
+.section .text
+
+ //! @function _print_sdl_error(char const * format)
+ function_begin _print_sdl_error
+
+ push %rdi
+ sub $8, %rsp
+
+ call SDL_GetError@PLT
+ mov %rax, %rsi
+
+ add $8, %rsp
+ pop %rdi
+
+ call printf@PLT
+
+ function_end
+
diff --git a/src/main.S b/src/main.S
index 50e894d..11b02e3 100644
--- a/src/main.S
+++ b/src/main.S
@@ -16,22 +16,6 @@
.section .text
- //! @function _print_sdl_error(char const * format)
- function_begin _print_sdl_error
-
- push %rdi
- sub $8, %rsp
-
- call SDL_GetError@PLT
- mov %rax, %rsi
-
- add $8, %rsp
- pop %rdi
-
- call printf@PLT
-
- function_end
-
function_begin main
define_local window_handle, 8
@@ -75,7 +59,6 @@
call SDL_Quit@PLT
- .Lsuccess:
lea greeting(%rip), %rdi
xor %rax, %rax
call printf@PLT