EEE 8086 Assembly Language Programming
EEE 8086 Assembly Language Programming
to
8086
Assembly Language
Programming
Prepared By
Dr. D. Jayakumar, M.Tech., Ph.D.,
Associate Professor, Dept Of ECE,
Kuppam Engineering College, Kuppam
What Is Assembly Language
• Machine-Specific Programming Language
– one-one correspondence between statements
and native machine language
– matches machine instruction set and
architecture
• IBM-PC Assembly Language
– refers to 8086, 8088, 80186, 80286, 80386,
80486, and Pentium Processors
What Is An Assembler?
• Systems Level Program
– translates assembly language source code to
machine language
• object file - contains machine instructions, initial
data, and information used when loading the
program
• listing file - contains a record of the translation
process, line numbers, addresses, generated code
and data, and a symbol table
Why Learn Assembly
Language?
• Learn how a • Allows creation of
processor works small and efficient
• Understand basic programs
computer architecture • Allows programmers
• Explore the internal to bypass high-level
representation of data language restrictions
and instructions • Might be necessary to
• Gain insight into accomplish certain
hardware concepts operations
Data Representation
• Binary 0-1 • Word - 16 Bits
– represents the state of – Each architecture may
electronic components define its own
used in computer “wordsize”
systems • Doubleword - 32 Bits
• Bit - Binary digit • Quadword - 64 Bits
• Byte - 8 Bits • Nybble - 4 Bits
– smallest addressable
memory location (on
the IBM-PC)
Numbering Systems
• Binary - Base 2 • Raw Binary format
– 0, 1 – All information is
• Octal - Base 8 coded for internal
storage
– 0, 1, 2, … 7
– Externally, we may
• Decimal - Base 10 choose to express the
– 0, 1, 2, …, 9 information in any
• Hexadecimal (Hex) numeration system, or
in a decoded form
– 0, 1, …, 9, A, B, …, F using other symbols
Decoding a Byte
• Raw • Machine Instruction
– 01010000b – Push AX
• Hex • ASCII Character code
– 50h – ‘P’
• Octal • Integer
– 1208 – 80 (eighty)
• Decimal • BCD
– 80d – 50 (fifty)
• Custom code ???
Machine Language
• A language of numbers, called the
Processor’s Instruction Set
– The set of basic operations a processor can
perform
• Each instruction is coded as a number
• Instructions may be one or more bytes
• Every number corresponds to an
instruction
Assembly Language vs Machine
Language Programming
These fields are separated by White Space (tab, blank, \n, etc.)
8086 Instruction - Example
Label Operator Operand[s] ;Comment
Label - INIT:
Operator - mov
Operands - ax and bx
Comment - alphanumeric string between ; and \n
NEG ;Negate
NOT ;Logical NOT
OR ;Logical inclusive OR
RCL ;Rotate through Carry Left
RCR ;Rotate through Carry Right
ROL ;Rotate Left
ROR ;Rotate Right
SAR ;Shift Arithmetic Right
SBB ;Subtract with Borrow
SCAS ;Scan memory at DI compared to AX
SHL/SAL ;Shift logical/Arithmetic Left
SHR ;Shift logical Right
SUB ;Subtract
TEST ;AND function to flags
XLAT ;Translate byte to AL
XOR ;Logical Exclusive OR
x86 Instruction Set Summary
(Control/Branch Cont.)
CALL ;Call
CLC ;Clear Carry
CLD ;Clear Direction
CLI ;Clear Interrupt
ESC ;Escape (to external device)
HLT ;Halt
INT ;Interrupt
INTO ;Interrupt on Overflow
IRET ;Interrupt Return
JB/JNAE ;Jump on Below/Not Above or Equal
JBE/JNA ;Jump on Below or Equal/Not Above
JCXZ ;Jump on CX Zero
JE/JZ ;Jump on Equal/Zero
JL/JNGE ;Jump on Less/Not Greater or Equal
JLE/JNG ;Jump on Less or Equal/Not Greater
JMP ;Unconditional Jump
JNB/JAE ;Jump on Not Below/Above or Equal
JNBE/JA ;Jump on Not Below or Equal/Above
JNE/JNZ ;Jump on Not Equal/Not Zero
JNL/JGE ;Jump on Not Less/Greater or Equal
x86 Instruction Set Summary
(Control/Branch)
JNLE/JG ;Jump on Not Less or Equal/Greater
JNO ;Jump on Not Overflow
JNP/JPO ;Jump on Not Parity/Parity Odd
JNS ;Jump on Not Sign
JO ;Jump on Overflow
JP/JPE ;Jump on Parity/Parity Even
JS ;Jump on Sign
LOCK ;Bus Lock prefix
LOOP ;Loop CX times
LOOPNZ/LOOPNE ;Loop while Not Zero/Not Equal
LOOPZ/LOOPE ;Loop while Zero/Equal
NOP ;No Operation (= XCHG AX,AX)
REP/REPNE/REPNZ ;Repeat/Repeat Not Equal/Not Zero
REPE/REPZ ;Repeat Equal/Zero
RET ;Return from call
SEG ;Segment register
STC ;Set Carry
STD ;Set Direction
STI ;Set Interrupt
TEST ;AND function to flags
WAIT ;Wait
Assembler Directives
.data
dos_print EQU 9 ;define a constant
strng DB 'Hello World',13,10,'$' ;Define the character string
.code
START: mov ax, SEG strng ;ax <-- data segment start address
mov ds, ax ;ds <-- initialize data segment register
mov ah, dos_print ;ah <-- 9 DOS 21h string function
mov dx,OFFSET strng ;dx <-- beginning of string
int 21h ;DOS service interrupt
mov ax, 4c00h ;ax <-- 4c DOS 21h program halt function
int 21h ;DOS service interrupt
END START
Program Statements
name operation operand(s) comment
• Operation is a predefined or reserved
word
– mnemonic - symbolic operation code
– directive - pseudo-operation code
• Space or tab separates initial fields
• Comments begin with semicolon
• Most assemblers are not case sensitive
Program Data and Storage
• Pseudo-ops to define • These directives
data or reserve require one or more
storage operands
– DB - byte(s) – define memory
– DW - word(s) contents
– DD - doubleword(s) – specify amount of
– DQ - quadword(s) storage to reserve for
run-time data
– DT - tenbyte(s)
Defining Data
• Numeric data values • A list of values may
– 100 - decimal be used - the
– 100B - binary following creates 4
– 100H - hexadecimal consecutive words
– '100' - ASCII DW 40CH,10B,-13,0
– "100" - ASCII • A ? represents an
• Use the appropriate uninitialized storage
DEFINE directive location
(byte, word, etc.) DB 255,?,-128,'X'
Naming Storage Locations
• Names can be • ANum refers to a byte
associated with storage location,
storage locations initialized to FCh
ANum DB -4 • The next word has no
DW 17 associated name
ONE
UNO DW 1 • ONE and UNO refer
X DD ? to the same word
• These names are called • X is an unitialized
variables doubleword
Arrays
• Any consecutive storage locations of the
same size can be called an array
X DW 40CH,10B,-13,0
Y DB 'This is an array'
Z DD -109236, FFFFFFFFH, -1, 100B
• Components of X are at X, X+2, X+4, X+8
• Components of Y are at Y, Y+1, …, Y+15
• Components of Z are at Z, Z+4, Z+8, Z+12
DUP
• Allows a sequence of storage locations to
be defined or reserved
• Only used as an operand of a define
directive
DB 40 DUP (?)
DW 10h DUP (0)
DB 3 dup ("ABC")
Word Storage