Skip to content

Printf Implementation with Additional Libraries

Notifications You must be signed in to change notification settings

V13kv/ownPrintf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Printf implementation

Shortened Assembly printf library implementation for Windows.

Motivation

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.

What printf specifiers are available?

There are %%, %c, %s, %d, %x, %o, %b (%b stands for "convert number to binary format") specifiers.

Program architecture

Program architecture

Description of libraries

  1. Strlib contains btoa, printString, PrintChar, itoa, memset.
  2. Winlib contains macroses-wrappers for Windows API: GetStdHandle, WriteFile, ExitProcess.
  3. Printflib contains only _myPrintf implementation.

Implementation details

  1. switch is implemented via jump table.
  2. itoa is implemented with the faster division if the given base (radix) is a power of two.
  3. GetNextPrintfArgument function gets each new unproceed printf argument using global variable (it is assumed that the number of arguments passed after format string is not less than the number of specifiers in it).

Compiling && Running

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

About

Printf Implementation with Additional Libraries

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published