Professional Documents
Culture Documents
12 Machine
Language
Instruction
Set
LEARNING OUTCOMES
By the end of this topic, you should able to:
1. List down all 14 registers for 8088 and its function; and
2. State the steps required to solve the problems of memory location.
INTRODUCTION
As explained earlier, Topic 12 will take you one-step further into Machine
Language programming. In this topic, forms of instructions will be explained.
We will discuss the Intel 8088 machine-language instruction set as an example.
As the instruction set for the 8088 machine is same as the 8086 machine, thus
whatever that relates with 8088 is true for 8086.
104 TOPIC 12 EXAMPLES OF MACHINE LANGUAGE INSTRUCTION SET
Instructions are executed either in an 8-bit or 16-bit form. A word does not
necessary start with a particular byte. However, the 8086 microprocessor is
more effective if the word starts with even-numbered bytes.
ACTIVITY 12.1
As the 8088 register is only 16 bit, logically it can only address up to 64K.
To solve this problem, the 8088 machine designer introduced the segment
concept. Each segment can hold up to 64K of memory address.
Each segment register points to a location in the 220 byte address space. This
location is the beginning of a segment. All the addresses are counted relatively
to the segment register.
To enable the segment register to refer to the location in the 220 byte address
space, it requires 20 bits. The technique used by the 8088 machine designer is by
using 16 bits and making the other 4 bits as zero.
TOPIC 12 EXAMPLES OF MACHINE LANGUAGE INSTRUCTION SET 105
Segment register and stack register was introduced to access data segment and
stack segment. Additional segment can be used to fulfil other requirements if
needed.
12.2 REGISTER
The process of registers was generally explained in Topic 11. In this section, the
usage of register for the 8088 will be explained in detail. The 8088 has 14
registers and all are 16-bits and different from each other. All these registers are
listed in Figure 12.1:
(a) AX is usually for arithmetic operation
(b) BX is used as pointer to the memory
(c) CX is used as a loop counter.
(d) DX is used as connection to AX for multiplication and division
instructions.
(e) SI and DI register is used for string operation. The operation usually needs
a source address that can be stated by using SI register in data segment
and destination address that can be stated by using DI register in the
additional segment.
(f) BP and SP register are usually used for addressing stacks. BP points to the
lower portion of the current stack and SP points to the upper portion.
(g) Four more registers are the segment registers that have been explained
earlier.
106 TOPIC 12 EXAMPLES OF MACHINE LANGUAGE INSTRUCTION SET
(h) The Instruction Pointer or IP (or PC) shows the next instruction that needs
to be executed.
(i) The flag is not a normal register. It is a collection of bits which can be set or
reset and tested by several of instructions. In short, the bits have the
following meanings:
D determines the direction string operation.
I enables interruptions
A enables trap
O is to set when overflow in arithmetic operation occurs.
S is to set to 1, if the arithmetic operation results in negative.
Z is to set to 1, if the arithmetic operation results in zero.
Name Explanation
AX AH AL Accumulator
BX BH BL Pointer and Arithmetic
CX CH CL Loop
DX DH DL Multiply, divide and I/O base
CS Code segment
DS Data Segment
SS Stack Segment
ES Additional Segment
IP Instruction Pointer
The AX, BX, CX and DX registers can be divided into the upper portion and
lower portion that can be addressed differently. When this method is applied,
all these registers form eight registers with one byte that can be used to
manipulate the quantity of a byte.
TOPIC 12 EXAMPLES OF MACHINE LANGUAGE INSTRUCTION SET 107
ACTIVITY 12.2
Why can AX, BX, CX, DX registers be divided into two portions?
For easier understanding, we have divided the instructions into a few groups
such as:
(a) The first group contains instructions that are used to transfer data in
machines in between registers, memory and stacks such as
(i) Transfer data from register or memory location
(ii) Enters data into stacks
(iii) Takes out data from a stack
(b) The second group executes signed and unsigned arithmetic. The
multiplication and division of a 32-bit output is stored in AX (lower
portion) and DX (upper portion). Among the instructions provided are:
(i) Add
(ii) Subtract
(iii) Multiply
(iv) Divide
(c) The third group involves the BCD operation (Binary codes Decimal).
(e) The fifth group involves instructions to test and compare and later jump
based on the result. The test result and instruction to compare are stored in
various bit of the FLAG register. Jxx is a conditional jump instruction set
that depends on the previous comparison result (such as bit in a FLAG).
(i) Jump to certain addresses.
(ii) Jump if a condition is fulfilled.
108 TOPIC 12 EXAMPLES OF MACHINE LANGUAGE INSTRUCTION SET
(f) The sixth group involves instructions that perform string operation.
(g) The last group is mixed instructions that are not suitable at any place. This
includes the I/O exchange and terminating the CPU processes.
(i) Terminate program executions
(ii) Input word from input base
(iii) Output word from output base
ACTIVITY 12.3
The 8088 instruction need to be encoded into binary form before it is executed.
Encoding Instructions are very complex.
Types of encoding used depend on the addressing mode. The 8088 has four
addressing modes such as immediate addressing, register addressing, direct
addressing and indirect addressing.
0 1 0 1 0 reg
8 bit
The first byte is an opcode that shows the code for that particular instruction.
mode is coded with two bits to show types of displacement that occurs.
Mod Displacement
00 DISP = 0, both types of displacement is not used
01 DISP = disp low, disp high no
10 DISP = disp low; disp high
11 r/m assume as register field
r/m shows the type of indirect addressing that is used whether indexes or
register base.
For example, if direct addressing is used, this actual address is stated by two
byte
displacement.
For example, the code for data transfer instruction from a memory to register is
coded by using two bytes as below:
Students who are interested in further reading on this encode instructions can
refer to any book that explains about microprocessor, such as:
R.W. Goody. 1993. Intel Microprocessors: Hardware Software and Application.
McGraw-Hill, Inc.
TOPIC 12 EXAMPLES OF MACHINE LANGUAGE INSTRUCTION SET 111
A flow chart is usually used by the programmer to make the task easier.
Example:
Write a program to read two numbers and store the total into memory at the
location 100000.
ACTIVITY 12.5
This topic explained the steps required before and after writing a machine
language program.
A flow chart is required before starting any program. It is not easy to create
a program without a flow chart, errors will be difficult to trace.