You are on page 1of 89

Chapter 3

INSTRUCTION SET AND ASSEMBLY


LANGUAGE PROGRAMMING
Course learning outcome –

• 3.1 EXPLAIN INSTRUCTION SET AND ASSEMBLY LANGUAGE.


• 3.1.1 Define Instruction set, machine and assembly language.
• 3.1.2 Describe the addressing modes using proper instruction format
• 3.1.3 Describe various types of addressing modes with example.

• 3.2 DEMONSTRATE SIMPLE PROGRAM IN ASSEMBLY


LANGUAGE
• ARITHMETIC OPERATION AND LOGIC OPERATION
3.1. UNDERSTAND THE INSTRUCTION SET AND
ASSEMBLY LANGUAGE.

• Message sent by programmers (program instructions)


understood by the computer and vice versa.
• Language that friendly to human also understandable to
computer systems.
• Three level of language:
• Low level – machine language
• Middle level – assembly language
• High level – high-level language
3.1.1 DEFINE INSTRUCTION SET,
MACHINE AND ASSEMBLY LANGUAGE
Instruction Set :

The complete collection of instructions that are


understood by a CPU
• Known also as Machine Code/Machine
Instruction
• Binary representation
• Usually represented by assembly codes
a) Machine language

• Machine language:
• Machine language is a binary program (or binary code).
• Natural language of a particular computer system.
• Strings of numbers or binary codes (0 or 1).
• Machine-dependant.
• Program written in any other language must be translated to binary
representation of instruction before they can be executed by
computer.
• Programmers need to know specifically the architecture of CPU.
Machine language
The program is
difficult to
The program is slow
understand
to key-in to the
computer due to the
input one bit by one
bit at a time

Limitations in It is very difficult


programming to program in machine
language.
using machine The programmer has to
language know details of hardware to
write program

The program is long and arduous.


The programmer has to remember a lot of
codes to write a program which results
in program errors
To overcome these problems, the use
of easily remembered code (mnemonic)
was introduced. It is apply with the use
of Assembly Language

6
b) Assembly language

• Assembly language:
• Assembly language is a symbolic representation of a machine language
of specific processor.
• Using english-like abbreviations (MUL).
• Assembler as translator.
• Assembly Process - Process of translating an assembly language
programs into a machine language programs. The assembly process is
straightforward (one-to-one mapping of assembly languages
statements to their machine language counterpart) and rather simple
• Programmer need to know the basic architecture.
• Why assembly language study is important?
• It clarifies the execution of instruction.
• It shows how the data represent in memory.
• It show how a program interacts with the operating system (OS),
processor and, input and output (I/O) system.
• It clarify how a program access external devices
• Sometimes difficult to access hardware drive and system tool if using (regis
transfer languages) RTL

Advantages using assembly languages


• Easy to make compilers, debuggers and other device tools.
• Allow accessing information that is not accessible (restricted) from high le
languages.
• More function library that can be used in programming development.
• Possibility to make library function that compatible with different comp
and operating system
• Disadvantages using assembly languages
• (Development) Requires longer development time
• (Reliability & Security) Easy to makes error
• (Debug) More possibility for errors
• (Maintain) Difficult to modify because it allows
unstructured code.
• (Portability) Difficult to porting to different platforms.
c) High level language

• High-level language:
• Using everyday English and common mathematical notation. (x = I + j)
• Overcome problems : assembly language require many instruction to
accomplish a simple task.
• Single instruction in HLL = several AL instructions.
• Compiler as translator.
• Programmers do not need to know the architecture of CPU.
Three Different Levels Of Language
Comparison Of Instructions Of Three
Different Languages
Comparison Of Instructions Of Three
Different Languages
Microprocessor overview
The term microprocessor typically refers to the central processing
unit (CPU) of a microcomputer, containing the arithmetic logic
unit (ALU) and the control units (CU).
Performs the main tasks for the computer system
• data transfer between (registers) and memory or I/O
• arithmetic and logic operations. Example: ADD, SUB, AND, OR, etc
• program flow via simple decisions. Example: Zero, Sign, Carry,
etc

8
3.1.2 DEMONSTRATE SIMPLE PROGRAM
IN ASSEMBLY LANGUAGE ARITHMETIC
OPERATION AND LOGIC OPERATION
a) INSTRUCTION FORMAT

• There are many MC68000 instructions. However, theses


instructions comply to a standard instruction format:
a) INSTRUCTION FORMAT

• LABEL – A user-defined symbol representing the address


associated with the instruction. Up to 8 alphanumeric, begin
with letter, terminated by a space.
• OPERATOR - A mnemonic code for MC68000 instructions. An
assembler directive / pseudo-instruction / pseudo-operation.
Macro call (repetitive instructions in a program which are
codified only once and can be used as many times as necessary)
• OPERAND – Depends on the operator, may has more than one
operand.
• COMMENT – Explanation about the execution of instruction.
• Data format - Byte | Word | Longword | Sign-extended
DATA FORMAT
• The physical operation of an instruction is manipulating data contained
in the internal register and memory locations. Thus it is essential to
familiarize the data format. In the operator field (column-2), we may see
the mnemonics are postfixed with symbol “.B”, “.W”, “.L”. This is actually
specifying the data size of operand (column-3) which is to be working on.
In other words, how many bits of the data cells are to be involved.
• One digit of hexadecimal is represented by 4 bits, 2n = 24 = 16. If 1 digit of
hexadecimal is labelled “H”, thus:

• p/s: We know that MC68000 has :


- 32 bits of data registers
DATA FORMAT
In other words, the prosffixer allow only a portion (at LSD side) of the whole
register bits is put on operation, whereas the remaining bit are either
unchanged or sign-extended. The minimum data size allowed is byte, thus we
may ignore the nibble: the postfixer provided are byte (.B), Word (.W) and
Lognword (.L), i.e. all bits in the registers.
DATA FORMAT

We may see the word “sign-extended” is frequently stated within this


module. We know that a data register can store up to maximum of 32 bits but
it also allows data operations to be working on with fewer bits (effective data)
at the LSB side; thus, the remaining bits have to be either unchanged or sign-
extended, i.e. filled with bits 1 or 0, depends on the sign bit (MSB) of the
effective data.
DATA FORMAT
DATA FORMAT
DATA FORMAT
B) Classification of instruction sets
The microprocessor is only accessible by the users via the instructions specifically
developed to accompany that particular hardware as a package. The instructions are just
like tools, a program may consists several of the instructions and some of them may be
used repeatedly. However, we still needs to know all the tools i.e. all the instructions
provided by the microprocessor manufacture, even thought we may not be using all of
them. Table below shows a list of MC68000 instructions in the alphabetic order. These
instructions are actually listed as reference instructions groups, where by each group in
the list may have several instructions with related function. For instance: ADD: ADD,
ADDA, ADDQ, ADDI, ADDX. MOVE: MOVE, MOVEA, MOVEQ
• Data Movement
• Arithmetic operation
• Logical operation
• Rotate and shift
• Control transfer group. (Jump and branch)
• Stack, stack pointer
• Block transfer.
• Other microprocessor instruction
B) Classification of instruction sets
b.1 DATA TRANSFER / MOVE GROUP
b.1 DATA TRANSFER / MOVE GROUP
b.1 DATA TRANSFER / MOVE GROUP

• Example 1:
• MOVE.W #$72,D1
• Before : D1 = $00200500
• After : D1 = $00200072
b.1 DATA TRANSFER / MOVE GROUP

• Example 2:
• MOVE.B D0,D1
• Before : D1 = $00200500 , D0 = $00002222
• After : D1 = $00200522 , D0 = $00002222
b.1 DATA TRANSFER / MOVE GROUP

$3000 32
$3001 43

• Example 3: $3002 98

• MOVE.B $3000,D1
• Before : D1 = $00200500
• After : D1 = $00200532

• Example 4:
• MOVE.W D6,$4000
• Before: D6 = $AB206541
• After : D6 = $AB206541
b.1 DATA TRANSFER / MOVE GROUP

• Example 5:
• MOVEA.W D6,A2
• Before : D6 = $AB206541 , A2 = $ABCD1234
• After : D6 = $AB206541 , A2 = $00006541
• Example 6:
• MOVEA.W D6,A2
• Before : D6 = $AB20A541 , A2 = $ABCD1234
• After : D6 = $AB20A541 , A2 = $FFFFA541
Example 7:
• MOVEA.L D6,A2
• Before : D6 = $AB206541 , A2 = $ABCD1234
• After : D6 = $AB206541 , A2 = $AB206541
b.1 DATA TRANSFER / MOVE GROUP

• Example 8:
• MOVEA.L A0,A1
• Before : A0 = $12345678 , A1 = $00000000
• After : A0 = $12345678, A1 = $12345678
b.1 DATA TRANSFER / MOVE GROUP

• Example 9:
• MOVEA.W D1,A1
• Before : D1 = $12345678, A1 = $11111111
• After : D1 = $12345678, A1 = $00005678
b.1 DATA TRANSFER / MOVE GROUP

• Example 10:
• MOVEA.L #$7000,A1
• Before : A1 = $12122030 , A1 = $00007000

• Example 11:
• MOVEA.L #$8000,A4
• Before : A4 = $12122030 , A1 = $FFFF8000
b.1 DATA TRANSFER / MOVE GROUP

Example 12: -128 (80) hingga 127 (7F)


• MOVEQ #$04,D3 (MOVEQ #XXX,Dn)
• Before : D3 = $AB206541
• After : D3 = $00000004
Example 13:
• MOVEQ #$80,D3
• Before : D3 = $AB206541
• After : D3 = $FFFFFF80
b.1 DATA TRANSFER / MOVE GROUP
Example 14:
• MOVEQ #$F1,D1
• Before : D1 = $12345678
• After : D3 = $FFFFFFF1
Example 15:
• MOVEQ #$71,D1
• Before : D1 = $12345678
• After : D3 = $00000071
b.1 DATA TRANSFER / MOVE GROUP
b.1 DATA TRANSFER / MOVE GROUP
Example 16:
EXG D1,D5
Before : D1 = $11223344 , D5 = $66778899
After : D1 = $66778899 , D5 = $11223344

Example 17:
SWAP D1
Before : D1 = $11223344
After : D1 = $33441122

Example 18:
CLR.B D1
Before : D1 = $11223344
After : D1 = $ 11223300
b. 2 ARITHMETIC operation
b. 2 ARITHMETIC

• Example 19:
• ADD.B D0, D1
• Before : D0 = $00002222 , D1 = $00004444
• After : D0 = $00002222 , D1 = $00204466
b. 2 ARITHMETIC

• Example 20:
• ADDI.W #$72,D1
• Before : D1 = $00200500
• After : D1 = $00200572

• Example 21:
• ADD.L D0,D1
• Before : D1 = $00200500 , D0 = $00002222
• After : D1 = $00202722 , D0 = $00002222

$3000 32
• Example 22:
$3001 43
• ADD.W $3000,D1
$3002 98
• Before : D1 = $00200500
• After : D1 = $00203743
B. 2 ARITHMETIC

• Example 23:
• ADDA.W D6,A2
• Before : D6 = $AB206541 , A2 = $ABCD1234
• After : D6 = $AB206541 , A2 = $ABCD7775
• Example 24:
• ADDA.L D6,A2
• Before : D6 = $AB20A541 , A2 = $ABCD1234
• After
Example 25: : D6 = $AB206541 , A2 = $56EDB775 , C = 1
ADDX.B D2,D3
Before : D2 = $AB206541 , D3 = $ABCD1234 , X = 1
After : D2 = $AB206541 , D3 = $AB206576 , X = 1
B. 2 ARITHMETIC

-128 (80) hingga 127 (7F)

• Example 26:
• ADDQ.B #$04,D3 (ADDQ #XXX,Dn)
• Before : D3 = $AB206541
• After : D3 = $AB206545
b. 2 ARITHMETIC
@ menunjukkan
nombor octal
% menunjukkan
Example 27: nombor binari
SUB.W #$80,D3
Before : D3 = $AB206541
After : D3 = $AB2064C1

Example 28:
SUB.W #$02,D1
Before : D1 = $12345678
After : D1 = $12345676
b. 2 ARITHMETIC
Example 29:
SUB.W D0,D1
Before : D0 = $12345678 , D1 = $98745432
After : D0 = $12345676 , D1 = $98760246
b. 2 ARITHMETIC
b. 2 ARITHMETIC
b. 2 ARITHMETIC
• Example 30:
• MULU #2,D2 ;16 bit x 16 bit = 32 bit
• Before : D2 = $AB206541
• After : D2 = $0000CA82
@ menunjukkan nombor
• Example 31: octal
% menunjukkan nombor

• MULU #2,D2
binari

• Before : D2 = $AB20FFFF
• After : D2 = $0001FFFE
• Example 32:
• DIVU #2,D3 ;32 bit / 16 bit = 16 bit lower (result)
16 bit upper ( remainder)
• Before : D3 = $00006541 6541F = 25921
• After : D3 = $000132A0 32A016 = 1296010
B.3 LOGICAL OPERATION
B.3 LOGICAL OPERATION

• Example 33:
• AND.B #$3E,D1
• Before : D1 = $12345674
• After : D1 = $12345634
B.3 LOGICAL OPERATION

• Example 34:
• OR.B D0,D1
• Before : D1 = $1234563E , D0 = $98765474
• After : D1 = $1234567E , D0 = $98765474
B.3 LOGICAL OPERATION

• Example 35:
• NOT.B D1
• Before : D1 = $12345655
• After : D1 = $123456AA
B.3 LOGICAL OPERATION

• Example 36:
• EOR.B D0,D1
• Before : D0 = $ 98765474 , D1 = $1234563E
• After : D0 = $98765474 , D1 = $1234364A
c) Addressing modes
c) Addressing modes

Microprocessor Programming Environment


c) Addressing modes

Internal registers of MC68000


This whole or portion of this structure will be used to show the
data changes and movement throughout the rest of this unit.
c) Addressing modes

MC68000 : 14
different
addressing modes
divided into 6
groups.
By understanding
the addressing
modes, we have
EA (effective
address).
EA will help us
identifies the
location of an
operand.
c) Addressing modes
c.1REGISTER DIRECT ADDRESSING

• Dn – Data register direct addressing. (D1,D2,D3,D4,D5,D6,D7)


• An – Address register direct addressing. (A1,A2,A3,A4,A5,A6,A7)

• Fastest and most compact because no reference to memory.


c.2 REGISTER INDIRECT ADDRESSING

• p/s: Using () for those address register which represented the register indirect addressing
c.2 REGISTER INDIRECT ADDRESSING
c.2 REGISTER INDIRECT ADDRESSING

+1 = byte
+2 = word
+3 = longword
c.2 REGISTER INDIRECT ADDRESSING

+1 = byte
+2 = word
+3 = longword
c.2 REGISTER INDIRECT ADDRESSING
c.2 REGISTER INDIRECT ADDRESSING
c.3 ABSOLUTE DATA ADDRESING
c.3 ABSOLUTE DATA ADDRESING
c.3 ABSOLUTE DATA ADDRESING
c.4 IMMEDIATE DATA ADDRESSING
c.4 IMMEDIATE DATA ADDRESSING
c.4 IMMEDIATE DATA ADDRESSING
c.4 implied ADDRESSING
INCORRECT INSTRUCTIONS

You might also like