Search code examples
winapiassemblymasm

Printing in MASM without includes or DOS interrupts?


sorry if this is a basic question, but I can't seem to find the answer anywhere online.

I am learning assembly. Dev environment is VS2013 & MASM on Windows 7. I have a decent understanding of string manipulation and now I am trying to print a char to the console. The methods that I can find on the internet involve including MASM files, using MessageBoxA, or modifying the project settings to use DOS interrupts.

Including external files and modifying project settings are two things that I definitely don't want to do. MessageBoxA seems cool, but is there not a way to print to console in pure ASM? Thanks!


Solution

  • Windows is not DOS and has not been for a long time. Windows NT based versions does not allow you to write directly to hardware without a kernel driver.

    If you don't care about Unicode then you just need to call GetStdHandle(STD_OUTPUT_HANDLE) to get a handle to stdout and then use this handle with WriteFile.

    Use WriteConsole to write Unicode strings if GetConsoleMode returns true.