EXTERNAL FUNCTIONS
External functions from libraries like libc can be used in assembly to perform common tasks without manually converting or formatting data. For example, the printf
function in libc accepts format strings and handles output formatting. To use libc functions in assembly, the function must first be declared or imported via an extern
directive. Then, during the linking stage, the assembly code is linked with the libc library using ld
along with the appropriate dynamic linking options. This approach lets you leverage powerful, pre-written routines without rewriting them in assembly.
COMMON LIBC FUNCTIONS USED IN ASSEMBLY
; SECTION: INCLUDE FILES
extern printf ; Declare printf as an external function (from libc)
section .data
; initialized data ; Initialized data (e.g., strings, format specifiers)
section .bss
; uninitialized data ; Uninitialized data (e.g., buffers, counters)
section .text ; Code section (actual instructions)
global _start ; Make the _start label visible to the linker
_start ; Entry point of the program
Last updated