What is Assembly Programming Language?
But before we start, let's first ask more foundational questions:
What Is Machine Language?
Although programmers tend to use C or C++ or Pascal these days, the language closest to the PC hardware is machine language. Not one second during a PCS powered on lifetime passes where the computer is not executing machine language.
Assembly Language Or Machine Language
To word this simply, you can say that say that assembly language is a human-readable text, and machine language is machine-readable binary code. When you program in assembly language, you are programming on the machine language level.
To program directly in machine language is tedious, so you use assembly language instead, and use an assembler to produce the actual machine code.
When To Use Assembly Language
I personally think that except as a learning exercise it's a waste of time writing something in asm that can be written acceptably fast in a high-level language.
Assembly language fits for the following:
- Low level control. When you need to change the flags, or the control registers of the processor, as when entering protected mode.
- Speed. Programs written in machine language execute fast! It can execute 10-100 times the speed of BASIC, and about twice as fast as a program written in C or Pascal.
- Time Critical Code. Critical sections of programs written in higher level languages, can be written in assembly to speed up sections.
- Small program size. When you write a TSR for example this is very useful. Writing interrupt handlers is where assembly language shines.
Assembly language is very flexible and powerful, anything that the hardware of the computer is capable of doing can be done in assembly.
Each type of CPU has its own machine language and assembly language, so an assembly language program written for one type of CPU won't run on another. In the early days of programming, all programs were written in assembly language. Now, most programs are written in high-level languages. Programmers still use assembly language when speed is essential or when they need to perform an operation that isn't possible in a high-level language.
Hello World in Assembly:
write(int fd, char *Buff, int NumBytes);