Department of Electrical and Electronic
Engineering
Khulna University of Engineering & Technology
Khulna-9203
Course code : EE 3214
Sessional on
Microprocessors, Micro-controllers and Peripherals
Presented By
Amit Kumer Podder
Experiment No. 06
(a) Introduction to 8086 assembly language
programming
(b)Introduction to serial monitor operation of
MDA-Win 8086 trainer kit
Experiment Name
7/3/2020 Amit Kumer Podder 2
The memory in 8086 systems is segmented with segments like code, data,
stack and extra segment.
While writing the assembly the beginning and end of different segments are
to be clearly indicated. This is done by segment directive.
Assembler Directive: a statement to give direction to the assembler
to perform task of the assembly process.
 Indicate how an operand or a section of the program is to be
processed by the assembler
It consists of two types of statements: instructions and directives
 Instructions: translated to the machine code by the assembler
 Directives are not translated to the machine codes
Assembler Directives
7/3/2020 Amit Kumer Podder 3
● SYMBOLS: to signify different components of the ALP (assembly Language
Program)
 Symbols consist of following characters:-
 Upper case & lower case alphabets: A to Z; a to z
 Digits: 0 to 9
 Special characters: $, ?, @, _ (underscore)
 No distinction between an uppercase and lowercase letter
 A hexadecimal no. starting with A to F must begin with “0” (zero) ; otherwise will be
taken as a symbol
● VARIABLE: these are symbols whose values can be varied while running a program
 Names of variables: should be meaningful to make program maintenanceeasy
 A variable can use: A to Z; a to z; 0 to 9; @; _ (underscore)
 Digit can not be used as 1st character of an Assembler variable
● CONSTANT: these are symbols whose values can not be varies while running a
program
 A numeric constant may be a binary, decimal or hexadecimal number.
 Symbols B, D & H must be used at the end of a binary, decimal
and hexadecimalnumber, respectively.
Important terms and rules
7/3/2020 Amit Kumer Podder 4
● Data declaration directives: DB, DW, DD, DQ, DT
● ASSUME
● END directives
● EQU Directive
● PROC
● ORG
● SEGMENT
● GROUP, INCLUDE, EVEN, ALIGN
● EXTRN, PUBLIC,
● TYPE, PTR,
● LENGTH, OFFSET
● NAME, LABEL, SHORT, GLOBAL
Assembler Directives
7/3/2020 Amit Kumer Podder 5
8086 supports Different data types. The data types unlike in high level language
which use keywords like INT, char, float etc., 8086 treats everything as a bytes
and according have directives for declaring type for Single byte, two byte ( a
word), double word, quad words, ten bytes etc, These are-
DB - Defined Byte. DB declares a variable of type byte and reserves one location in
memory for the variable of type byte.
Example
num1 DB 15h
DW – Defined Word. The DW directive is used to declare a WORD type
variable - A WORD occupies 16 bits or (2 BYTE).
● examples:
 WORDS DW 1234H, 3456H; Declares an array of 2 words and initialize them with
thespecified values
DD - Defined Double Word. The DD directive is used to declare a DWORD
- A DWORD double word is made up of 32 bits =2 Word's or 4 BYTE.
● examples:
 ARRAY DD 25629261H;
Data Declaration Directives
7/3/2020 Amit Kumer Podder 6
DQ-Define Quadword
This directive is used to define a variable of type quadword or to
reserve storage location of type quadword in memory. For example
Quad_word DQ 1234123412341234H
DT-Define Ten Bytes
This directive is used to define a variable which is 10 bytes in
length or to reserve 10 bytes of storage in the memory. For example
Ten_bytes DT 11223344556677889900
Data Declaration Directives
7/3/2020 Amit Kumer Podder 7
ORG directive: This directive instructs the assembler to start the
program in memory from the offset mentioned in the argument of
ORG.
● The ORG directive allows you to set the location counter
to a desired value at any point in the program.
Example:
 The statement ORG 2000H tells the assembler
to set the location counter to 2000H.
Origin Directives
7/3/2020 Amit Kumer Podder 8
● END - End Program
● ENDP - End Procedure
● ENDS - End Segment
● END – it signifies the end of the program module
 The assembler will ignore any statement after an END
directive
● ENDP - indicates the end of a procedure
 Syntax: Procedure_name ENDP
● ENDS - indicates the end of a logical segment
 Syntax: Segment_name ENDS
End Directives
7/3/2020 Amit Kumer Podder 9
PROC (Procedure) Directive
● PROC - The PROC directive is used to identify the
start of a procedure. The term near or far is used to
specify the type of the procedure.
● Example:
 SMART PROC FAR ; This identifies that the start of a
procedure named as SMART and instructs the assembler that
the procedure is far .
7/3/2020 Amit Kumer Podder 10
● ASSUME Directive - The ASSUME directive is used to tell the
assembler that the name of the logical segment should be used
for a specified segment. The 8086 works directly with only 4
physical segments: a Code segment, a data segment, a stack
segment, and an extra segment.
Example:
● ASSUME CS:CODE ;This tells the assembler that the logical
segment named CODE contains the instruction statements for
the program and should be treated as a code segment.
● ASSUME DS:DATA ;This tells the assembler that for any
instruction which refers to a data in the data segment, data
will found in the logical segment DATA.
Assume Directives
7/3/2020 Amit Kumer Podder 11
The offset directive will be used where the offset from starting of the segment is
required in the program. The example of OFFSET is:
MOV SI, OFFSET string1; copies the offset of string1 in SI register
OFFSET directive
DUP directive is used to duplicate the basic data definition 'n' number of times;
or saying it the other way is that DUP is used to declare array of Size n.
ARRY DB 10 dup (0), declares array of 10 byte.
DUP directive
This directive is used to instruct the assembler that a Specified name or label will
be accessed from other modules.
Example: PUBLIC MULIPLIER, INTEREST_RATE
PUBLIC directive
Other Directives
7/3/2020 Amit Kumer Podder 12
Equate (EQU) Directive
● EQU - This EQU directive is used to give a name to some
value or to a symbol. Each time the assembler finds the
name in the program, it will replace the name with the
value or symbol you given to that name.
● Example:
 FACTOR EQU 03H ; you has to write this statement at the starting
of your program
 later in the program you can use this as follows :
 ADD AL, FACTOR ;
7/3/2020 Amit Kumer Podder 13
TYPE, PTR(POINTER)
● TYPE - instructs the assembler to determine the type of a variable and
determines the number of bytes specified to that variable.
Example:
 Byte type variable – assembler will give a value 1 Word type variable – assembler will
give avalue 2 Double word type variable – assembler will give a value 4 ADD BX, TYPE
WORD_ ARRAY ; hear we want to increment BX to point to next word in an array of
words.
● PTR (POINTER) : used to assign a specific type to a variable or a label. It is
necessary to do this in any instruction where the type of the operand is not
clear.
Example:
 INC [BX]; It will not know whether to increment the byte pointed to by BX. We use
thePTR operator to clarify how we want the assembler to code the instruction.
 INC BYTE PTR [BX] ; This statement tells the assembler that we want to increment
thebyte pointed to by BX.
 INC WORD PTR [BX] ; This statement tells the assembler that we want to increment
theword pointed to by BX. The PTR operator assigns the type specified before PTR to the
variable specified after PTR.
7/3/2020 Amit Kumer Podder 14
8086 Programming using Assembler Directives
●Basic structure of a program:
Name_data segment SEGMENT
Data declaration statement 1
:
:
Data declaration statement n
DATA ENDS
Name_codeseg SEGMENT
ASSUME CS:CODE, DS:DATA, ES:EXTRA, SS: STACK
START:
Program line 1
:
:
Program line n
Name_codeseg ENDS
END START
7/3/2020 Amit Kumer Podder 15
● Program to multiply 2 16-bit words in memory locations called MULTIPLICAND
and MULTIPLIER. Result is stored in memory location PRODUCT.
DATA SEGMENT
MULTIPLICAND DW 204A H; 1ST Word
MULTIPLIER DW 3B2A H; 2nd word
PRODUCT DW 2 DUP(0); sets aside storage for 2 words in memory and gives starting address of 1st word
the name PRODUCT. The DUP(0) part of the statement tells assembler to initialize 2 words to all zeros.
DATA ENDS
CODE SEGMENT
ASSUMER CS:CODE, DS:DATA;
START:
MOV AX, DATA
MOV DS, AX
MOV AX, MULTIPLICAND;
MUL MULTIPLIER;
MOV PRODUCT, AX;
MOV PRODUCT+2, DX;
INT 3
CODE ENDS
END START
Example
7/3/2020 Amit Kumer Podder 16
Recapitulations of Addressing Mode
7/3/2020 Amit Kumer Podder 17
Recapitulations of Addressing Mode
7/3/2020 Amit Kumer Podder 18
Now Start Programming on
MDA-Win 8086 Training Kit
7/3/2020 Amit Kumer Podder 19
Program : To study different addressing modes of 8086 Microprocessor
CODE SEGMENT
ASSUME CS:CODE, DS:CODE, ES:CODE, SS:CODE;
ORG 1000H
MOV AX,0001H
MOV DS,AX
MOV ES,AX
;
MOV BX,2000H
MOV AX,[BX]
MOV CH,[BX+2]
MOV CL,[BX+3]
;
MOV BP,BX
MOV DX,DS:[BP+4]
MOV SI,ES:[BP+6]
MOV BX,[BP+8]
INT 3;
CODE ENDS
END.
7/3/2020 Amit Kumer Podder 20

8086 Assembly Language and Serial Monitor Operation of 8086 Trainer Kit

  • 1.
    Department of Electricaland Electronic Engineering Khulna University of Engineering & Technology Khulna-9203 Course code : EE 3214 Sessional on Microprocessors, Micro-controllers and Peripherals Presented By Amit Kumer Podder Experiment No. 06
  • 2.
    (a) Introduction to8086 assembly language programming (b)Introduction to serial monitor operation of MDA-Win 8086 trainer kit Experiment Name 7/3/2020 Amit Kumer Podder 2
  • 3.
    The memory in8086 systems is segmented with segments like code, data, stack and extra segment. While writing the assembly the beginning and end of different segments are to be clearly indicated. This is done by segment directive. Assembler Directive: a statement to give direction to the assembler to perform task of the assembly process.  Indicate how an operand or a section of the program is to be processed by the assembler It consists of two types of statements: instructions and directives  Instructions: translated to the machine code by the assembler  Directives are not translated to the machine codes Assembler Directives 7/3/2020 Amit Kumer Podder 3
  • 4.
    ● SYMBOLS: tosignify different components of the ALP (assembly Language Program)  Symbols consist of following characters:-  Upper case & lower case alphabets: A to Z; a to z  Digits: 0 to 9  Special characters: $, ?, @, _ (underscore)  No distinction between an uppercase and lowercase letter  A hexadecimal no. starting with A to F must begin with “0” (zero) ; otherwise will be taken as a symbol ● VARIABLE: these are symbols whose values can be varied while running a program  Names of variables: should be meaningful to make program maintenanceeasy  A variable can use: A to Z; a to z; 0 to 9; @; _ (underscore)  Digit can not be used as 1st character of an Assembler variable ● CONSTANT: these are symbols whose values can not be varies while running a program  A numeric constant may be a binary, decimal or hexadecimal number.  Symbols B, D & H must be used at the end of a binary, decimal and hexadecimalnumber, respectively. Important terms and rules 7/3/2020 Amit Kumer Podder 4
  • 5.
    ● Data declarationdirectives: DB, DW, DD, DQ, DT ● ASSUME ● END directives ● EQU Directive ● PROC ● ORG ● SEGMENT ● GROUP, INCLUDE, EVEN, ALIGN ● EXTRN, PUBLIC, ● TYPE, PTR, ● LENGTH, OFFSET ● NAME, LABEL, SHORT, GLOBAL Assembler Directives 7/3/2020 Amit Kumer Podder 5
  • 6.
    8086 supports Differentdata types. The data types unlike in high level language which use keywords like INT, char, float etc., 8086 treats everything as a bytes and according have directives for declaring type for Single byte, two byte ( a word), double word, quad words, ten bytes etc, These are- DB - Defined Byte. DB declares a variable of type byte and reserves one location in memory for the variable of type byte. Example num1 DB 15h DW – Defined Word. The DW directive is used to declare a WORD type variable - A WORD occupies 16 bits or (2 BYTE). ● examples:  WORDS DW 1234H, 3456H; Declares an array of 2 words and initialize them with thespecified values DD - Defined Double Word. The DD directive is used to declare a DWORD - A DWORD double word is made up of 32 bits =2 Word's or 4 BYTE. ● examples:  ARRAY DD 25629261H; Data Declaration Directives 7/3/2020 Amit Kumer Podder 6
  • 7.
    DQ-Define Quadword This directiveis used to define a variable of type quadword or to reserve storage location of type quadword in memory. For example Quad_word DQ 1234123412341234H DT-Define Ten Bytes This directive is used to define a variable which is 10 bytes in length or to reserve 10 bytes of storage in the memory. For example Ten_bytes DT 11223344556677889900 Data Declaration Directives 7/3/2020 Amit Kumer Podder 7
  • 8.
    ORG directive: Thisdirective instructs the assembler to start the program in memory from the offset mentioned in the argument of ORG. ● The ORG directive allows you to set the location counter to a desired value at any point in the program. Example:  The statement ORG 2000H tells the assembler to set the location counter to 2000H. Origin Directives 7/3/2020 Amit Kumer Podder 8
  • 9.
    ● END -End Program ● ENDP - End Procedure ● ENDS - End Segment ● END – it signifies the end of the program module  The assembler will ignore any statement after an END directive ● ENDP - indicates the end of a procedure  Syntax: Procedure_name ENDP ● ENDS - indicates the end of a logical segment  Syntax: Segment_name ENDS End Directives 7/3/2020 Amit Kumer Podder 9
  • 10.
    PROC (Procedure) Directive ●PROC - The PROC directive is used to identify the start of a procedure. The term near or far is used to specify the type of the procedure. ● Example:  SMART PROC FAR ; This identifies that the start of a procedure named as SMART and instructs the assembler that the procedure is far . 7/3/2020 Amit Kumer Podder 10
  • 11.
    ● ASSUME Directive- The ASSUME directive is used to tell the assembler that the name of the logical segment should be used for a specified segment. The 8086 works directly with only 4 physical segments: a Code segment, a data segment, a stack segment, and an extra segment. Example: ● ASSUME CS:CODE ;This tells the assembler that the logical segment named CODE contains the instruction statements for the program and should be treated as a code segment. ● ASSUME DS:DATA ;This tells the assembler that for any instruction which refers to a data in the data segment, data will found in the logical segment DATA. Assume Directives 7/3/2020 Amit Kumer Podder 11
  • 12.
    The offset directivewill be used where the offset from starting of the segment is required in the program. The example of OFFSET is: MOV SI, OFFSET string1; copies the offset of string1 in SI register OFFSET directive DUP directive is used to duplicate the basic data definition 'n' number of times; or saying it the other way is that DUP is used to declare array of Size n. ARRY DB 10 dup (0), declares array of 10 byte. DUP directive This directive is used to instruct the assembler that a Specified name or label will be accessed from other modules. Example: PUBLIC MULIPLIER, INTEREST_RATE PUBLIC directive Other Directives 7/3/2020 Amit Kumer Podder 12
  • 13.
    Equate (EQU) Directive ●EQU - This EQU directive is used to give a name to some value or to a symbol. Each time the assembler finds the name in the program, it will replace the name with the value or symbol you given to that name. ● Example:  FACTOR EQU 03H ; you has to write this statement at the starting of your program  later in the program you can use this as follows :  ADD AL, FACTOR ; 7/3/2020 Amit Kumer Podder 13
  • 14.
    TYPE, PTR(POINTER) ● TYPE- instructs the assembler to determine the type of a variable and determines the number of bytes specified to that variable. Example:  Byte type variable – assembler will give a value 1 Word type variable – assembler will give avalue 2 Double word type variable – assembler will give a value 4 ADD BX, TYPE WORD_ ARRAY ; hear we want to increment BX to point to next word in an array of words. ● PTR (POINTER) : used to assign a specific type to a variable or a label. It is necessary to do this in any instruction where the type of the operand is not clear. Example:  INC [BX]; It will not know whether to increment the byte pointed to by BX. We use thePTR operator to clarify how we want the assembler to code the instruction.  INC BYTE PTR [BX] ; This statement tells the assembler that we want to increment thebyte pointed to by BX.  INC WORD PTR [BX] ; This statement tells the assembler that we want to increment theword pointed to by BX. The PTR operator assigns the type specified before PTR to the variable specified after PTR. 7/3/2020 Amit Kumer Podder 14
  • 15.
    8086 Programming usingAssembler Directives ●Basic structure of a program: Name_data segment SEGMENT Data declaration statement 1 : : Data declaration statement n DATA ENDS Name_codeseg SEGMENT ASSUME CS:CODE, DS:DATA, ES:EXTRA, SS: STACK START: Program line 1 : : Program line n Name_codeseg ENDS END START 7/3/2020 Amit Kumer Podder 15
  • 16.
    ● Program tomultiply 2 16-bit words in memory locations called MULTIPLICAND and MULTIPLIER. Result is stored in memory location PRODUCT. DATA SEGMENT MULTIPLICAND DW 204A H; 1ST Word MULTIPLIER DW 3B2A H; 2nd word PRODUCT DW 2 DUP(0); sets aside storage for 2 words in memory and gives starting address of 1st word the name PRODUCT. The DUP(0) part of the statement tells assembler to initialize 2 words to all zeros. DATA ENDS CODE SEGMENT ASSUMER CS:CODE, DS:DATA; START: MOV AX, DATA MOV DS, AX MOV AX, MULTIPLICAND; MUL MULTIPLIER; MOV PRODUCT, AX; MOV PRODUCT+2, DX; INT 3 CODE ENDS END START Example 7/3/2020 Amit Kumer Podder 16
  • 17.
    Recapitulations of AddressingMode 7/3/2020 Amit Kumer Podder 17
  • 18.
    Recapitulations of AddressingMode 7/3/2020 Amit Kumer Podder 18
  • 19.
    Now Start Programmingon MDA-Win 8086 Training Kit 7/3/2020 Amit Kumer Podder 19
  • 20.
    Program : Tostudy different addressing modes of 8086 Microprocessor CODE SEGMENT ASSUME CS:CODE, DS:CODE, ES:CODE, SS:CODE; ORG 1000H MOV AX,0001H MOV DS,AX MOV ES,AX ; MOV BX,2000H MOV AX,[BX] MOV CH,[BX+2] MOV CL,[BX+3] ; MOV BP,BX MOV DX,DS:[BP+4] MOV SI,ES:[BP+6] MOV BX,[BP+8] INT 3; CODE ENDS END. 7/3/2020 Amit Kumer Podder 20