Assembler and machine code

    Machine code is the only one programming language understandible by computer, it's so said "wired" into the processor. All high-level programming languages are actually only programs in machine code simulating those particular languages. But the machine code is written in memory or processor as bytes or bits in form of ones and zeros. Constructing programs in form of a string of numbers would be too complicated, thus programmers use (nearly like in case of high-level programming languages) words representating machine instructions, so called assembler. (In this document I use word assembler for simplicity reasons also there where would be the phrase "machine code" more suitable.) So each instruction has its meaning, form in assembler and a representation number in machine code, for example:

DEC BX
01001011b=4Bh=75
lessen the number in register BX by 1

    To convert assembler into machine code you can use various programs. For our necessities I chose the Netwide Assembler (NASM). You can download it's functioning version (including a comfortable editor) here [664 240 bytes]. (Then you have to edit file nasmide.ini and put there the correct full path to the file nasm16.exe.) We write programs for NASM using this scheme:

[BITS 16]
[ORG 0x0100]

[SECTION .text]

    Write the program in assembler here
MOV AX,4C00h
INT 21h
;exits the program

    You can launch the program using hot key CTRL+F9. If everything is correctly, the program will run.

    If we want to use inline assembler in Turbo Pascal, we can use this scheme:

asm
    Write the programm in assembler here
end;

    If we want to use a label or a variable we just have to write its name beginning at the left margin and then we can use it:

less_bx:  DEC BX
variab  DB 0