Skip to content

tvomacka/AssemblyHelloWorld

Repository files navigation

AssemblyHelloWorld

Once, this was meant to be a simple testing project for assembly, but suddenly it grew to be a collection of various small learning samples. This includes working with command line, memory allocation, and various simple algorithms. See the TODOs to see what's planned next.

Disclaimer: This repo will probably stay in a very unorganized manner. It is not meant to have great (or any, for that matter) PR culture, tests, or fancy commit notations. It is here for one purpose - to learn assembly.

Microsoft Reference

[Windows 10] Using C/C++ project in VS2022

  • Add a .asm file into source files
  • Right click the project and go to Build Dependencies->Build Customizations..., check the masm (.targets, .props) checkbox
  • Right click the .asm file and go to Properties, set the Item Type to Microsoft Macro Assembler
  • Project properties: Linker->System Enable Large Addresses=No
  • Project properties: Linker->Advanced Entry Point="main"

[Windows 10] Using Command Line

  • Open x64 Native Tools Command Prompt for VS 2022
  • Note this is not the same as the Developer Command Prompt for VS 2022 or Developer Power Shell for VS 2022!
  • cd into the source directory and run the following command to generate helloWorld.exe
    ml64 helloWorld.asm /link /subsystem:console /entry:main
    

Getting Rid of Dependencies

hello1.asm

Is a minimal Hello World in x64 MASM (no library includes), but needs to be linked against kernel32.lib during the link part of the build.

ml64 hello1.asm /c /Zi
link hello.obj kernel32.lib /subsystem:console /entry:main /debug

barebones.asm

MASM x64 "Hello World" via direct syscalls (no imports).

ml64 barebones.asm /link /entry:start /subsystem:console

Currently builds and runs, but outputs nothing, the problem is most probably with having incorrect stdout handle for the OS version. Will have to investigate.

I/O

printNum.asm

Outputs a number to console as a text, manually converting the number to a string. Currently works only on positive integers. But should serve as PoC. The algorithm works by repeated division of the provided input by base (10, but could easily be modified to include other bases) and writing the modulo to the first memory index, shifting all of the previously written characters to the next memory location.

Includes memory allocation on heap for the converted string value.

ml64 printNum.asm /c /Zi
link printNum.obj kernel32.lib /subsystem:console /entry:main /debug

printNumStack.asm

The algorithm in printNum.asm works, but maybe it should be rewritten using stack instead of pushing all of the previously written chars to the right before writing a new one. And this is what this file does.

ml64 printNumStack.asm /c /Zi
link printNumStack.obj kernel32.lib /subsystem:console /entry:main /debug

Working with Command Line

clargs.asm

Reads the command line arguments and writes them to the console output.

ml64 clargs.asm /c /Zi
link clargs.obj kernel32.lib /subsystem:console /entry:main /debug

TODO:

  • refine the clargs sample so that we essentially get the argc/argv structure known from C

  • numeric parsing

  • command line argument parsing

  • learn about referencing other files in .asm - how do I call proc defined in other .asm?

  • learn about argument parsing, stack and instruction pointers

  • learn about shellcode

  • Rabin-Karp algorithm

  • enhance the intToStr to allow using negative numbers

  • working with stack

  • number output to console (int to str)

About

Simple learning project for various assembly tasks

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published