Beruflich Dokumente
Kultur Dokumente
ASSEMBLY LANGUAGE
- a low level language which employs English-like syntax.
- gives a detailed step-by-step sequence of operations.
• We will be writing programs in the assembly language form from given mathematical
statements and expressions.
• We will be assuming that there is only one register being used, i.e., the accumulator.
• For statements with multiple operations, the following hierarchy will have to be
followed:
() Parentheses
^ Exponentiation
*, / Multiplication, Division
+, - Addition, Subtraction
• We will be dealing with straight line programs and programs that involve
looping/branching.
Example:
1. B = L + U * E
LOAD U
MPY E
ADD L
STORE B
2. B = R + E * A – K
LOAD E
MUL A
ADD R
SUB K
STORE B
3. B = (A / S * I – C / O) / N
LOAD C
DIV O
STORE TEMP
LOAD A
DIV S
MPY I
SUB TEMP
DIV N
STORE B
4. D = E / N
A=T+E/N–O
LOAD E
DIV N
STORE D
ADD T
SUB O
STORE A
BASICON
ASSEMBLY AND MACHINE LANGUAGE
5. E = A – T
B=R+A–T*S
LOAD A
SUB T
STORE E
LOAD T
MPY S
STORE TEMP
LOAD R
ADD A
SUB TEMP
STORE B
B. Looping/ Branching
1. IF A >= B THEN C = A – B
LOAD A
SUB B
BGE L1
BR L2
L1 LOAD A
SUB B
STORE C
L2 STOP
2. IF A > B THEN D = C + E;
D=B
LOAD A
SUB B
BGT L1
BR L2
L1 LOAD C
ADD E
STORE D
L2 LOAD B
STORE D
STOP
BASICON
ASSEMBLY AND MACHINE LANGUAGE
3. IF X <= Y THEN Z = X * Y
ELSE Z = X / Y
LOAD X
SUB Y
BLE L1
LOAD X
DIV Y
BR L2
L1 LOAD X
MPY Y
L2 STORE Z
STOP
MACHINE LANGUAGE
- the program form that is stored in memory.
- represented as a sequence of digit patterns.
• When programs are stored in memory, they occupy certain locations with
corresponding addresses. These addresses are to be used in locating certain
operands as well as in locating program segments when branching.
• If we assume that each instruction occupies three memory spaces for this particular
hypothetical computer, then the increment in the actual address will be by three.
BASICON
ASSEMBLY AND MACHINE LANGUAGE
• Using example B-1 in the assembly language generation, and assuming that our
starting address is 000100, the actual address and corresponding machine language
will be as follows:
Actual Address Symbolic Assembly Language Machine Language
Address
000100 LOAD A 000000124
000103 SUB B 030000125
000106 BGE L1 310000112
000109 BR L2 300000121
000112 L1 LOAD A 000000124
000115 SUB B 030000125
000118 STORE C 010000126
000121 L2 STOP 100000100
000124 A DC 1
000125 B DC 1
000126 C DC 1
000127 END
Symbol Table:
Label Address
L1 000112
L2 000121
A 000124
B 000125
C 000126
Note:
The operand address for the command STOP refers to the address of the first
executable command of the program, which, in this case, is in location 000100.
• ASSEMBLER DIRECTIVES
1. DS (Define Storage)
- instructs the assembler to allocate memory space for variables.
Examples:
A DS 1 {one location (space) is set for variable A}
R DS 3 {three consecutive locations are set aside for R}
2. DC (Define Constant)
- allocates a cell and sets its value to a certain constant.
Examples:
TWO DC 2 {sets the value of the variable TWO to 2}
PI DC 3.14 { sets the value of the variable PI to 3.14}
3. END
- notifies the assembler that the end of the program has been reached.