Microprocessor Based System: Muhammad Syargawi B. Abdullah Photonics Lab, Mimos Berhad For Unikl, Miit Sept 2012
Microprocessor Based System: Muhammad Syargawi B. Abdullah Photonics Lab, Mimos Berhad For Unikl, Miit Sept 2012
IED24103
Programming Intel 8086 Microprocessor
; Add data
Start ADD AL, 07H 07H into AL
; move data
MOV AX, 0A05H 0A05H into AX
Programming Format ctn...
• Label – optional: alphanumeric string
– 1st character must be a-z, A-Z, ?, @, _, $
• Opcode – assembly language instruction
– mnemonic an instruction format for humans
– assembler translates mnemonic into hexadecimal opcode (e.g.
MOV is F8H)
• Operand – 0-3 pieces of data required by instruction
– can be several different forms
– delineated by commas
– immediate, register name, memory data, & memory address
• Comment: Extremely useful
– rule of thumb: 1 comment per instruction
Instruction Types
34 12
If DS:0204H contains
0256H, then AX will
contain whatever is
stored at DS:0256H AX = 1234
Addressing Modes For Data
Transfer
• Based addressing mode
– The offset address of the operand is given by the
sum of contents of the BX or BP registers and 8-bit
or 16-bit displacement
suppose BX contains
0200H, then data is
MOV DX, [BX+04H]
moved from location
DS:0204H
Addressing Modes For Data
Transfer
• Indexed addressing mode
– the operands offset address is found by adding
the content of SI or DI register with 8-bit or 16-bit
displacements
suppose SI contains
0200H, then data is
MOV BX, [SI+04H]
moved from location
DS:0204H
Addressing Modes For Data
Transfer
• Based-Indexed addressing mode
– the offset address of the operand is computed by
summing the base register (BX or BP) and the
content of an index register (SI or DI)
• PUSH Operand
– It push specified word (operand) to top of the stack
– E.g.:
PUSH BX
• POP Destination
– Pop the word (operand) from top of the stack to the
specified location (destination)
– Destination can be a general purpose register, segment
register (except CS) or memory location
– E.g.:
POP AX
General Purpose Data Transfer
• INC Source
– It increments the byte or word by one
– The operand can be a register or memory location
– It effects AF, OF, PF, SF, ZF flags
– CF is not effected
– E.g.:
INC AX
Arithmetic
• DEC Source
– It decrements the byte or word by one
– The operand can be a register or memory location
– It effects AF, OF, PF, SF, ZF flags
– CF is not effected
– E.g.:
DEC AX
• NEG Source:
– It creates 2’s complement of a given number
– That means, it changes the sign of a number
Arithmetic
• IMUL Source
– It is a signed multiplication instruction
Arithmetic
• DIV Source
– It is an unsigned division instruction
– It divides word by byte or double word by word
– The operand is stored in AX, divisor is source and
the result is stored as:
AH = remainder AL = quotient
• IDIV Source
– It is a signed division instruction
Arithmetic
• NOT Source
– It complements each bit of source to produce 1’s
complement of the specified operand
– The operand can be a register or memory location
Bit Manipulation
• OR Destination, Source
– It performs OR operation of destination and
source
– Source can be immediate number, register or
memory location
– Destination can be register or memory location
– Both operands cannot be memory locations at the
same time
– CF and OF become zero after the operation
– PF, SF and ZF are updated
Bit Manipulation
• CALL Destination
– This instruction is used to call a subroutine or
function or procedure
– The address of next instruction after CALL is saved
onto stack
• RET
– It returns the control from procedure to calling
program
– Every CALL instruction should have a RET
Program Execution Transfer
• JMP Destination
– This instruction is used for unconditional jump
from one place to another
• Loop Destination
– This is a looping instruction
– The number of times looping is required is placed
in the CX register
– With each iteration, the contents of CX are
decremented
– ZF is checked whether to loop again or not
String
• SCAS String
– It scans a string
– It compares the string with byte in AL or with
word in AX
String
• REP (Repeat):
– This is an instruction prefix
– It causes the repetition of the instruction until CX
becomes zero
– E.g.:
REP MOVSB STR1, STR2
– It copies byte by byte contents
– REP repeats the operation MOVSB until CX
becomes zero
Processor Control
Opcode Purpose
STC It sets the carry flag to 1
CLC It clears the carry flag to 0
CMC It complements the carry flag
It sets the direction flag to 1.
STD If it is set, string bytes are accessed from higher
memory address to lower memory address.
It clears the direction flag to 0.
CLD If it is reset, the string bytes are accessed from
lower memory address to higher memory address.
Assembler Directives
Directives Purpose
To inform the assembler the name of the logical
ASSUME
segment it should use for a specified segment
E.g.: ASSUME DS:DATA
• Tells the assembler that for any program instruction
which refers to the data segment, it should use the
logical segment called DATA
Assembler Directives
Directives Purpose
Define byte. To declare a byte variable or set aside
DB one or more storage locations of type byte in
memory
E.g.: TEMP_VALUE DB 36H
• Tells the assembler to reserve 1 byte of memory for a
variable named TEMP_VALUE and to put the value 36H in
that menory location when the program is loaded into
RAM
Assembler Directives
Directives Purpose
Define word. Tells the assembler to define a
DW variable of type word or to reserve storage
locations of type word in memory.
Define double word. To declare a variable of type
DD double word or restore memory locations which
can be accessed as type double word.
Define quad word. To tell the assembler to declare
DQ a variable with length of 4 words or to reserve 4
words of storage in memory.
Assembler Directives
Directives Purpose
Define ten bytes. To inform the assembler to define
DT a variable which is 10 bytes in length or to reserve
10 bytes of storage in memory.
Equate. To give name to some value or symbol.
Every time the assembler finds the given name in
EQU
the program, it will replace the name with the
value or symbol we have equated with that name.
Procedure. To identify the start of a procedure or
PROC
subroutine.
Assembler Directives
Directives Purpose
Originate. Changes the starting offset address of
ORG the data. It allows to set the location counter to a
desired value at any point in the program.
E.g.: ORG 3000H
• Tells the assembler to set the location counter to address
3000H
Assembler Directives
Directives Purpose
End program. This directive indicates the assembler
that this is the end of the program module. The
END
assembler ignores any statements after an END
directive.
End procedure. It indicates the end of the
ENDP
procedure or subroutine to the assembler.
End segment. This directive is used with the name
of the segment to indicate the end of that logical
ENDS segment.
E.g.: CODE SEGMENT ; start code segment
END SEGMENT ; end code segment
Assembly Language Development
Tools
• To develop an assembly language program, we
need certain program development tools.
• The tools are very handful for engineers or
programmers to write, edit, assemble, debug,
simulate and load the assembly code into
targeted hardware.
Assembly Language Development
Tools
Tools Purpose
A program which allows us to create an assembly code program. As
we type the assembly codes, the editor stores the ASCII codes for
Editor
letters and numbers in successive RAM location. The code’s source
files need to be saved with .ASM extension.
To translate the assembly language mnemonics into machine
language (i.e. binary codes). The assembler reads the source file and
generates two files: object file (.OBJ) and list file (.LST).
Assembler The object file consists of binary codes for the instructions and
information about the addresses of the instructions. After further
processing, the contents of the file will be loaded into memory and
run. A listing file can be used to see what error the assembler
encountered.
Assembly Language Development
Tools
Tools Purpose
A program to connect several object files into one large object file.
While writing a large program, it is better to divide the program into
Linker several modules (modular type of programming). Each module can
be individually written, tested & debugged. Then all modules are
linked together to form one functioning program.
An emulator is a mixture of hardware and software. It is usually
Emulator used to test and debug the hardware and software of an external
system such as the prototype of microprocessor based instrument.
Assembly Language Development
Tools
Tools Purpose
A program to load your object code program into system memory,
execute the program, and troubleshoot or debug it. The debugger
always looks into the contents of registers and memory location s
after the program has been run.
With debugger, we can also change the contents of the register and
Debugger memory locations and return the program. Some debuggers allow
you to halt the running program after each instruction has been
executed so that the contents of memory or registers can be
checked or altered.
Object File
(machine code, .HEX)
Source File
Assembler
(text, .ASM)
List File
(text file, .LST, may include symbol table)
Processes for Creating
Executable Code