Search code examples
compilationcompiler-constructionbinary

Compiling Binary


I would like to get a feel of how computers originally worked. I know initially with computers such as ENIAC, they physically had to plug in wires in the correct order to make their programs execute. They later used punch cards and finally then came up with assembly language(s). It just build upward from there with FORTRAN, COBOL, etc. Is there any way I am compile 0s and 1s on my computer. If I open textedit, and type in a specific sequence of zeroes and ones, then is how can I make that a binary file and not a text with a sequence of ASCII characters? I am open to any method. (Disclaimer: I know doing things in binary takes forever, I just want to learn how to very basic things.)


Solution

  • The easiest way to do this is to start with an assembler of your choice, in an IDE if you like. Use some sort of debugger (such as an IDE) so you can see the effect of your code without also having to write to console or file.

    Rather than writing only binary as text digits, write a complete assembler source using data elements instead of instructions.

    So, instead of

    .code
    main proc
        mov eax,5               
        add eax,6               
    main endp
    end main
    

    you could write:

    main proc
        db 10111000b, 00000101b, 00000000b, 00000000b, 00000000b
        db 10000011b, 11000000b, 00000110b
    main endp
    end main
    

    db means define byte and the b suffix means binary.

    And, with this, you'd be all set up to cheat, but I won't tell you how until you ask so I don't spoil the fun for you.

    Here is a good tutorial for getting started on Windows with MASM and Visual Studio 2015.