Assembly Language Programming Fundamentals

Synthesis
In this Topic will be treated the following subjects: Assembly Language, Assembler, Assembler Directives, Macro Assembler, Linker, Longword, Word, Byte, Running an Assembly Program Example.

Assembly is the closest language to the computer hardware. After Assembly comes only the hardware codes. In Assembly the
machine code instructions  are represented by mnemonics. Memory addresses and constants are written in a symbolic form, as happens in languages of higher level of abstraction. An Assembly Language is very concerned with the current hardware processor, therefore it is strongly dependent on the architecture of the processor. This is a great contrast with high level programming languages like Java, Pascal and C, whose one the more important aims is to abstract the current hardware complexities, eventual deficiencies and  specific dependencies.

An Assembly language is made up of two types of statements:

a. The executable instruction
An executable instruction is one of the processor's valid instructions and is translated into the appropriate machine code form
by the Assembler.

b. The Assembler Directive.
Assembler directives tell the Assembler something about the program. Basically, they link symbolic names to values, allocate storage, set up predefined constants, and control the processing of the Assembly code. Some examples of Assembler Directives are: TTL, EQU, DC, DS, ORG, SECTION and END. These will be treated in the sub topic Assembler Directives.

For running an Assembly program is necessary to have an Assembler. An Assembler is a program. It is responsible
to compile and convert the Assembly code to the current hardware instructions set, this is also known as the "assembly phase". The Assembler input is an Assembly programmed code and the output will be the Object Code, which is nothing more than a machine runable instructions set.

Furthermore, the Assembler may have some powerful tools like the Linker and the Macro Assembler.
The Linker permits a program to be developed as a series of separate and independents modules. These modules can be linked to form a complete program. A module can be written and the linker told about all the variables an names that are declared outside the module. During the assembly phase, real addresses of operands are replaces by dummy addresses. When the modules are linked, the linker is able to put together all the various modules, and any dummy addresses are replaced by the actual addresses.
The Macro Assembler is an often available tool. As its name says, it permits the programmer define macros. A macro is a unit of in-line code that is given a name by the programmer and that can be called rather like a subroutine. Unlike a subroutine, the full code of the macro is embedded in the program each time it is used. Thus, the programmer avoids to writing certain sequences of instructions repeatedly.
Three important concepts in an Assembly program are the longword, word and byte. In the case of the processor Motolora 68000, such concepts relate do the operand's sizes: 8, 16 or 32 bits. A 32 bits entity is called a longword, a 16 bits entity is called a word and a 8 bits entity is called a byte.
Here under there is an Assembly Program Example:

TTL            Program to Input Text to a Buffer
EQU           $08                                                    ASCII code for back space
EQU           $7F                                                    ASCII code for delete
EQU           $0D                                                   ASCII code for carriage return

ORG          $004000                                             Data Origin
DS.B          64                                                       Reserve 64 bytes for line buffer

ORG          $001000                                              Program Origin
LEA.L        LINE_BUFFER.A2                             A2 points to line buffer
BSR           GET_DATA                                        Call subroutine to get input
CMP.B      #BACK_SPACE, D0                          Test for backspace
BEQ          MOVE_LEFT                                      If backspace than deal with it
CMP.B      #DELETE, D0                                      Test for delete
BEQ          CANCEL                                             If delete then deal with it
CMP.B      #CARRIAGE_RET, D0                       Test for carriage return
BEQ          EXIT                                                    If carriage return then deal with it
MOVE.B   D0, (A2)+                                            Else store input in memory
BRA          NEXT                                                  Repeat

END