You are on page 1of 10

Topic Examples of

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

12.1 ADDRESS SPACE


The 8088 was designed to be able to address up to 220 byte. It is numbered
sequentially starting from 0.

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.

For addressing up to 220 , the 8088 microprocessor requires a 20-bit register.

ACTIVITY 12.1

In your opinion, why does addressing up to 220 require a 20-bit


register? Discuss.

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.

There are four types of segment such as:


(a) Code segment
(b) Data segment
(c) Stack segment and
(d) Additional segment

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

For example, if segment register has the value

0101 1011 0010 0011

The address that it shows is 0101 1011 0010 0011 0000

If the Instruction pointer has the value

0011 0011 1111 1010

Thus, the memory address that it shows is actually

0101 1011 0010 0011 0000


0011 0011 1111 1010 +

0101 1110 0110 0010 1010

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

SI Source pointer for string


DI Destination pointer for string
BP Base pointer
SP Stack pointer

CS Code segment
DS Data Segment
SS Stack Segment
ES Additional Segment

IP Instruction Pointer

FLAGS Word program status

Figure 12.1: Register 8088

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?

12.3 INSTRUCTION SET


The instruction set that is provided by the 8088 contains 300 forms of machine
language instructions.

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).

(d) The fourth group involves Boolean instructions and rotate/shift


manipulating bits in a word or bit in a few ways. Boolean AND, OR and
NOT are examples of operations.

(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

(iii) Jump if value of CX is 0.


(iv) Call the procedure.
(v) Return to the procedure.

(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

In your opinion, why does the 8086 have many instructions?

12.4 ENCODE INSTRUCTION


ACTIVITY 12.4

Why do encoding instructions use the binary form?

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.

12.4.1 Immediate Addressing


This type of instruction involves two or three bytes. For example, instruction to
transfer data immediately into register is

1 0 1 1 w reg data data


8 bit 8 bit 8 bit
TOPIC 12 EXAMPLES OF MACHINE LANGUAGE INSTRUCTION SET 109

reg shows the register used, as coded in Table 12.2:

Table 12.1: Encoding Instructions

16 bit (w = 1) 8 bit (w = 0) Segment


000 AX 000 AL
001 CX 001 CL 00 ES
010 DX 010 DL 01 CS
011 BX 011 BL 10 SS
100 SP 100 AH 11 DS
101 BP 101 CH
110 SI 110
To transfer contents from the accumulator into the memory, the instruction
code is:

101000 w address address


8 bit 8 bit 8 bit

12.4.2 Register Addressing


The Instruction code that uses this addressing usually consists of one byte. An
example code for the instruction to enter register contents into the stack is:

0 1 0 1 0 reg

8 bit

12.4.3 Direct / Indirect Addressing


Generally, these types of instructions consist of two, three or four bytes.

opcode mode xxx r/m disp low disp high


8 bit 8 bit 8 bit 8 bit

The first byte is an opcode that shows the code for that particular instruction.

The second byte is to determine the displacement that will occur.


110 TOPIC 12 EXAMPLES OF MACHINE LANGUAGE INSTRUCTION SET

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

Figure 12.2: Few types of displacement

r/m shows the type of indirect addressing that is used whether indexes or
register base.

If an instruction involves register, thus xxx represent registers.

Displacement is used to indicate the actual address of a data in a memory.


The actual address calculation depends on the type of addressing mode used.

For example, if direct addressing is used, this actual address is stated by two
byte
displacement.

For indirect addressing, it involves index

Actual address = displacement + index register

For example, the code for data transfer instruction from a memory to register is
coded by using two bytes as below:

100010dw mode reg r/m


8 bit 8 bit

reg shows the register used.


d shows the transfer direction, whether from register or to the register. The
actual address of data in a memory can be counted based on the mode value
and r/m.

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

12.5 WRITING PROGRAM


Writing a program in machine language is very difficult because a programmer
needs to give instructions step-by-step in a very low level.

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.

The flow chart to solve this problem is:

To write the program in machine language, programmers need to perform


following steps:-
(a) To read the first number
Instruction to read input from an input base that will read the input and
store it in an AX register. Instructions to store data in AX register into CX
register.
112 TOPIC 12 EXAMPLES OF MACHINE LANGUAGE INSTRUCTION SET

(b) To read the second number


Instructions to read input from an input base into AX.
(c) TOTAL First number + Second Number
Instruction to add for AX and CX register contents and later store into AX
register.
(d) Store TOTAL at the location 100000
Instruction to store the AX contents into memory location 100000.
(e) End.
Instruction to terminate the program.

ACTIVITY 12.5

1. If there is a program to be developed, is there possibility for the


flow chart to change?
2. Draw a flow chart that can read 10 numbers and later print the
total. And then, explain step by step what needs to be done by
the machine language programmer to convert the flow chart
into machine language.

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.

Address space Instruction set


Register Encode Instruction

You might also like