DFC10093 Chapter 3

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 108

CHAPTER 3

INSTRUCTION SET AND ASSEMBLY


LANGUAGE PROGRAMMING
COURSE LEARNING OUTCOME –
WRITE A SIMPLE PROGRAM IN ASSEMBLY LANGUAGE TO
PERFORM GIVEN TASK. (C3, P3, A2, PLO1, PLO2, PLO4)

3.1 UNDERSTAND 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 APPLY ASSEMBLY LANGUAGE.


3.2.1 Write a simple program in assembly language for:
a. arithmetic operation
b. logic operation
3.2.2 Use tools in analyzing and debugging assembly language programs
INTRODUCTION
Capability of processor determine the capability of the computer system.
Therefore, processor is the key element or heart of a computer system.
Other than PC, microprocessors are used in various computerized system
such as industrial automation.
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). Binary
code is a sequence of instruction and operand in binary that list the
exact representation instruction as they appear in computer
memory.
• Natural language of a particular computer system.
• Strings of numbers or binary codes (0 or 1).
• Machine-dependant (differ from one µP to other µP.
• 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
understand

The program is slow


to key-in to the
computer due to the
input one bit by one
Limitations in bit at a time
programming
using machine
language
The program did not
specify the tasks we
perform require a
computer.

The program
is long and
arduous
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. Assembly language is a form that is
very dependent on the underlying architecture.
• Using english-like abbreviations (MUL).
• Assembler as translator.
• Assembler - Translate ordinary mnemonics such as MOVE Data,
Acc, into their corresponding machine language (the only form of
instruction that computer can executed)
• 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
(register 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
level languages.
• More function library that can be used in programming development.
• Possibility to make library function that compatible with different compiler
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 DESCRIBE ADDRESSING
MODES USING PROPER
INSTRUCTION FORMAT
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
- 32 bits of address registers, but only 24 least significant bits are
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

Example 3:
$3000 32
• MOVE.B $3000,D1
$3001 43
• Before : D1 = $00200500
$3002 98
• 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 , A4 = $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 = $00004466
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

Example 22: $3000 32


• ADD.W $3000,D1 $3001 43
• Before : D1 = $00200500 $3002 98
• 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 : D6 = $AB206541 , A2 = $56EDB775 , C = 1

Example 25:
ADDX.B D2,D3
Before : D2 = $AB206541 , D3 = $ABCD1234 , X = 1
After : D2 = $AB206541 , D3 = $AB206576 , X = 1
B. 2 ARITHMETIC

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


• 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 D1,D0
Before : D0 = $12345678 , D1 = $98745432
After : D0 = $12340246, D1 = $98745432
B. 2 ARITHMETIC
B. 2 ARITHMETIC
B. 2 ARITHMETIC
Example 30:
• MULU #2,D2 ;16 bit x 16 bit = 32 bit
• Before : D2 = $AB206541
@ menunjukkan
• After : D2 = $0000CA82 nombor octal
% menunjukkan
Example 31: nombor binari

• MULU #2,D2
• Before : D2 = $AB20FFFF
FFFF16 = 6553510
• After : D2 = $0001FFFE 1FFFE16 = 13107010

Example 32:
• DIVU #2,D3 ;32 bit / 16 bit = 16 bit lower (result)
16 bit upper ( remainder)
• Before : D3 = $00006541
654116 = 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

HEXA convert to BINARI


7416 = 11101002
3E16 = 1111102
3416 = 1101002
B.3 LOGICAL OPERATION
Example 34:
• OR.B D0,D1
• Before : D1 = $1234563E , D0 = $98765474
• After : D1 = $1234567E , D0 = $98765474

HEXA convert to BINARI


7416 = 11101002
3E16 = 1111102
7E16 = 1111 1102
B.3 LOGICAL OPERATION
Example 35:
• NOT.B D1
• Before : D1 = $12345655
• After : D1 = $123456AA

HEXA convert to BINARI


5516 = 010101012
AA16 = 101010102
B.3 LOGICAL OPERATION
Example 36:
• EOR.B D0,D1
• Before : D0 = $ 98765474 , D1 = $1234563E
• After : D0 = $98765474 , D1 = $1234364A

HEXA convert to BINARI


7416 = 11101002
3E 16 = 01111102
4A16 = 10010102
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
+4 = longword
C.2 REGISTER INDIRECT ADDRESSING

- 1 = byte
- 2 = word
- 4 = 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
EASY68K

You might also like