Ch10 Assem

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

ELE 3230

Microprocessors and Computer


Systems
Chapter 10
Assembly Language
Instruction Set
(Hall: Ch3; Brey: Ch7-1; Triebel: Ch3)

Programming in 8088/8086
a Three levels of languages available to program a microprocessor:
Machine Languages, Assembly Languages, and High-level Languages.
a Machine Language
` A sequence of binary codes for the instruction to be executed by microcomputers.
` Long binary bits can be simplified by using Hexadecimal format.
` It is difficult to program and error prone.
` Different uP uses different machine codes.
Example:

Contents
(hex)

Operation

11100100

E4

INPUT FROM

00101H

00000101

05

Port 05H

00102H

00000100

04

ADD

00103H

00000111

07

07H

00104H

11100110

E6

OUTPUTO

00105H

00000010

02

PORT 02

Memory
Address

Contents
(binary)

00100H

ELE 3230 - Chatper 10

Programming in 8088/8086 (cont.)


a Assembly Language
` To simplify the programming, assembly language is used.
` Assembly language uses 2- to 4-letter mnemonics to represent each instruction
type.
Subtraction is represents by SUB
` Four fields in assembly language statement:
Label, OP Code, Operand and Comment fields.
` Programs will be translated into machine language, by Assembler, so it can be
loaded into memory for execution.

a High-Level Language
` High level languages, like C, Basic or Pascal, can also be used to program
microcomputers.
` An interpreter or a compiler is used to translate high level language statement to
machine code.
` High level language is easier to read by human and is more suitable when the
programs involves complex data structures.
ELE 3230 - Chatper 10

Assemblers
a Programming the instructions directly in machine code is possible but very
time consuming as each basic instruction can have one of several different
machine codes depending on how the data is stored
a The process of converting the microprocessor instructions to the binary
machine code can be performed automatically by a computer program,
called an ASSEMBLER. Popular assemblers include IBM macro Assembler,
Microsoft Macro Assembler (MASM) and Borland Turbo Assembler
(installed on IE NT Network).
a Most assemblers accept an input text file containing lines with a rigorously
defined syntax split into four fields.

Label Mnemonic/directive Operands


comment
FRED:
ADD
AL,0FH ;Adds 0FH to register AL
a Not all fields need to be present in a line. Eg. A line can be just a comment
line if it starts with semicolon;

ELE 3230 - Chatper 10

Program Trapping (Tracing)


a Most microprocessors have a mode of operation which allows a program
to be stopped after each instruction and the execution of another program
(debugging program) to allow program debugging (examining the
operation of a program to find errors [bugs]).
a Debugging mode is entered by setting the T (trap) flag in the FLAGS
register of the Intel 80X86 (or the trace flag in the status register of the
Motorola 68000). ( check ex. 12-1 of Breys)
a Typical debugging methods
` Single stepping and examine the register and memory contents after each
instruction (time consuming)
` Program tracing (i.e. finding the sequence of instructions being executed by
the program)
` Breakpoints (stopping a program at a point decided by the programmer to
allow examination of the registers)
` Memory dump (outputting the contents of memory)
ELE 3230 - Chatper 10

Source Codes, Object Codes and


Linking
a Source code is the text written by the programmer in assembly language
(or any other programming language)
a Object code is the binary code obtained after running the assembler (or
compiler if the source is in a high level language).
a Modules of a program may be written separately and linked together to
form a executable program using a linker.
a The linker joins the object code of the different modules into one large
object file which is executable. Most assemblers on IBM PCs produce
object files which must be linked (even if there are no separate modules).

ELE 3230 - Chatper 10

Source Codes, Object Codes and


Linking (cont.)
S o u rc e
C ode

S o u rc e
C ode

A s s e m b le

C o m p ile

O b je c t
Code

O b je c t
C ode
L in k e r

L in k e r

S o u rc e
C ode
A s s e m b le
O b je c t
C ode
L in k e r

O b je c t c o d e
(e x e c u ta b le )

ELE 3230 - Chatper 10

Fields in Assembler
<label> <Mnemonic or directive> <operands> <;comment>
a Comment field contains internal program documentation to improve
human readability - use meaningful comments
a Operand field contains data or address used by the instruction.

The following conventions typically apply:


MOV AX, [10H+01]
; loads word into AX

Mnemonic Destination
Address

source address (offset 11H)


brackets [ ] denote address

ELE 3230 - Chatper 10

Fields in Assembler (cont.)


<label> <Mnemonic or directive> <operands> <;comment>
a Mnemonic/directive field contains the abbreviation for the processor
instruction (eg. MOV) or an assembler DIRECTIVE. A directive produces no
object code but is used to control how the assembler operates.
Examples of directives include
- indicates the end of a program listing,
END
FRED LABEL NEAR
- defines FRED as a near label
TOM EQU 1000H
- defines TOM as the number 1000H

a Label field contains a label which is assigned a value equal to the address
where the label appears.

ELE 3230 - Chatper 10

Assembler Programs
a Writing assembler program takes longer time than programming in a high
level language like C.
Example:
Two long integers may be added in C by

X=Y+Z;
A similar addition in assembler needs 6 lines of assembler:

MOV AX, [Y]


MOV DX [Y+2]
ADD AX, [Z]
ADC DX, [Z+2]
MOV [X], AX
MOV [X+2], DX

;loads from address [Y] into register AX


;loads high order word to DX
;add low order word;
;add with carry high order word;
;store result at memory address X

ELE 3230 - Chatper 10

10

So Why Program in Assembler?


a Assembler language instruction has a one to one correspondence with
the binary machine code: the programmer controls precisely all the
operations performed by the processor (a high level language relies on a
compiler or interpreter to generate the instructions).
a Assembler can generate faster and more compact programs
a Assembler language allows direct access and full control of input/output
operations
a High level language programs are easier to write and develop than
assembler language programs

ELE 3230 - Chatper 10

11

Advantages of High-level languages


a Block structure code: programs are most readable when they are
broken into logical blocks that perform specific function.

a Productivity: easier to program


a Level of complexity: no need to know the hardware details
a Simple mathematics formula statement
a Portability: only need to change the compiler when it is ported to other
machine

a Abstract data types: different data types like floating-point value,


record and array, and high precision value.

a Readability

ELE 3230 - Chatper 10

12

Intel 8088/8086 Instruction Set


Overview
a Intel 8088 has ninety basic (ie not counting addressing mode
variants) instructions
a Instructions belong to one of the following groups: data
transfer, arithmetic, logic, string manipulation, control
transfer and processor control.

ELE 3230 - Chatper 10

13

Intel 8088/8086 Instruction Set


Overview
Data Transfer (14)
MOV, PUSH, POP, XCHG, IN, OUT, XLAT, LEA, LDS, LES,LAHF, SAHF, PUSHF, POPF

Arithmetic (20)
ADD, ADC, INC, AAA, BAA, SUB, SSB, DEC, NEG, CMP, AAS, DAS, MUL, IMUL, AAM,
DIV, IDIV, AAD, CBW, CWD

Logic (12)
NOT, SHL/SAL, SHR, SAR, ROL, ROR, RCL, RCR, AND, TEST, OR, XOR

String Manipulation (6)


REP, MOVS, XMPS, SCAS, LODS, STOS

Control Transfer (26)


CALL, JMP, RET, JE/JZ, JL/JNGE, JLE/JNG, JB/JNAE, JBE/JNA, JP/JPE, JO, JS,
JNE/JNZ, JNL/JGE, JNLE/JG, JNB/JAE, JNBE/JA, JNP/JPO, JNO, JNS, LOOP,
LOOPZ/LOOPE, LOOPNZ/LOOPNE, JCXZ, INT, INTO, IRETR

Processor Control (12)


CLC, CMC, STC, CLD, STD, CLI, STI, HLT, WAIT, ESC, LOCK, NOP
ELE 3230 - Chatper 10

14

Instruction Set (cont.)


a Microprocessors can perform a range of basic operations defined by their
instruction set
a The instruction set is a set of binary codes known as op-codes which can
be decoded by the microprocessors control unit
a Op-codes are often combined with some address information to specify
the location of the operands (the data for the instruction)
15

0
o p -c o d e

d a ta /a d d re s s

d a ta /a d d re s s

E x a m p le m a c h in e c o d e in s tru c tio n

ELE 3230 - Chatper 10

15

Instruction Set
a The total number of instruction in an instruction set is limited by the
number of possible bits available for encoding the op-code. - Usually not
all the bits in a word are used for the op-code since some bits are needed
for the addressing information. This limit may be worked around by using
2,3 or more words for instructions (slower since more read cycles from
memory are needed)
a Short word length machines suffer from limited instruction set and
memory address space. Hence long word length machines are more
powerful.

ELE 3230 - Chatper 10

16

Intel 8088 Machine Code


Instruction Format
a Machine code for an instruction consists of a binary code of variable length
(typically 2 bytes but can be 1 byte or 4 bytes depending on the instruction).
Machine code includes all the necessary information (opcode, address,
data) for an instruction
a The machine codes for the Intel 8088 is listed in the Intel Microprocessor
data book. Example : Move and jump instructions (pp47 Halls)(Breys ch4-1)

ELE 3230 - Chatper 10

17

Intel 8088 Machine Code


Instruction Format (cont.)

ELE 3230 - Chatper 10

Ex: B4 06 =? MOV AH, 6

18

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy