Shortened Assembly printf
library implementation for Windows.
The idea is to understand how printf
works from the inside and understand the intricacies of writing applications for the Windows system in NASM using the Windows API.
There are %%, %c, %s, %d, %x, %o, %b
(%b
stands for "convert number to binary format") specifiers.
- Strlib contains
btoa
,printString
,PrintChar
,itoa
,memset
. - Winlib contains macroses-wrappers for Windows API:
GetStdHandle
,WriteFile
,ExitProcess
. - Printflib contains only
_myPrintf
implementation.
switch
is implemented viajump table
.itoa
is implemented with the faster division if the given base (radix) is a power of two.GetNextPrintfArgument
function gets each new unproceed printf argument using global variable (it is assumed that the number of arguments passed afterformat string
is not less than the number of specifiers in it).
Compile, link and run examples:
cd examples
nasm.exe -f win32 ownPrintf.asm -o ownPrintf.obj
gcc.exe -m32 -o ownPrintf
.\ownPrintf.exe
Compile printflib.asm
, link and run with another program (e.g. with C program)
cd examples
<path_to_nasm_assembler>\nasm.exe -f win32 ..\lib\printflib.asm
<path_to_mingw32_gcc>\gcc.exe -c test.c -o test.o
<path_to_mingw32_gcc>\gcc.exe test.o ..\lib\printflib.obj -o test.exe
.\test.exe