From ba84097e38b02b3a213fbfc37f0ee2312ce6aa20 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 20 Feb 2026 12:50:05 +0100 Subject: refactor: simplify error logging --- src/error.S | 17 +++++++++++------ src/main.S | 6 +++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/error.S b/src/error.S index 50597dd..8075c26 100644 --- a/src/error.S +++ b/src/error.S @@ -3,20 +3,25 @@ #ifndef __STDC_VERSION__ +.section .rodata + + sdl_error_format: .string "%s: %s\n" + .section .text - //! @function _print_sdl_error(char const * format) + //! @function _print_sdl_error(char const * prefix) + //! + //! @param (%rdi) prefix The prefix to be printed in front of the error message function_begin _print_sdl_error - push %rdi sub $8, %rsp + push %rdi call SDL_GetError@PLT - mov %rax, %rsi + mov %rax, %rdx - add $8, %rsp - pop %rdi - + mov (%rsp), %rsi + lea sdl_error_format(%rip), %rdi call printf@PLT function_end diff --git a/src/main.S b/src/main.S index 63fa359..d4c897f 100644 --- a/src/main.S +++ b/src/main.S @@ -13,9 +13,9 @@ // callee-saved: RBX, RSP, RBP, R12-R15 .section .rodata - failed_to_create_renderer: .string "Renderer could not be created\nSDL_error: %s\n" - failed_to_create_window: .string "Window could not be created\nSDL_error: %s\n" - failed_to_initialize_sdl: .string "SDL could not be initialized\nSDL_error: %s\n" + failed_to_create_renderer: .string "Renderer could not be created" + failed_to_create_window: .string "Window could not be created" + failed_to_initialize_sdl: .string "SDL could not be initialized" succeeded_to_create_renderer: .string "Renderer created successfully!\n" succeeded_to_create_window: .string "Window created successfully!\n" -- cgit v1.2.3