You are on page 1of 38

DIGITAL LOGIC

AND MICROPROCESSOR

DR.M.SINDHUJA
ASSISTANT PROFESSOR(SENIOR GRADE)
SCHOOL OF ELECTRONICS
VIT, CHENNAI
MODULE -7

PROGRAMMING MODEL OF 8086


MACHINE LANGUAGE VS ASSEMBLY LANGUAGE PROGRAM
MACHINE LANGUAGE PROGRAMMING
coding of program in terms of 0 and 1.
 Memory control in hands of programmer
 Programming, coding, Memory Management is tedious
Possibility of human errors
Only program designer able to understand programs
ASSEMBLY LANGUAGE PROGRAMMING
Assembly language programming is simpler
Instruction Mnemonics are directly written in assembly language programs
Programs are reachable and understandable
Storage defined facilities and document facilities are available
Address values and constant are identified by Labels
ASSEMBLER DIRECTIVES OF 8086
Assembler is a program convert assembly language program into machine codes
During conversion, address of each label is initialised and substitutes the values for each of the
constants and variables
Assembler generates the equivalent machine code for all mnemonics and data.
 Assembler may find out syntax errors but logical or other programming error are not found.
For completing the task, assembler need hint from programmer (programmer should mention
constants, variables, logical names of the segments, types of the different routines and modules,
and end of file)
These type of hints given to the assembler using predefined alphabetical strings called
assembler directives.
 Assembler directives help the assembler understand the assembly-language programs properly
and generate the machine codes.
ASSEMBLY DIRECTIVES USED IN 8086 PROGRAMMING
DB: Define Byte EQU: Equate

DW: Define Word LABEL: Label


DQ: Define Quadword
LENGTH: Byte Length of a Label
DT: Define Ten Bytes
ASSUME: Assume Logical Segment Name NAME: Logical Name of a Module

END: End of Program OFFSET: Offset of a Label


ENDP: End of Procedure ORG: Origin
ENDS: End of Segment
PROC: Procedure
Directives are used in assembly language programming
practice using Microsoft Macro Assembler or Turbo SEG: Segment of a label
Assembler
DB- DEFINE BYTE
 It is used to reserve byte or bytes of memory location in the available memory
Example: RANKS DB 01H, 02H, 03H tells the assembler to reserve 3 bytes of
memory location for a variable named RANKS and to put the above specified
value in that memory location when the program is loaded into RAM.
DW- DEFINE WORD
It tells the assembler to reserve number of memory words instead of bytes
Example: WORDS DW 1234H, 4567H, 784BH (6bytes) and intialize the
specified values. During intialize, LB are stored at lower memory address while
UB are stored at higher memory address
DQ- DEFINE QUADWORD
This directive is used to tell the assembler to reserve 4 words of Memory for the
specified variable and may initialize with the specified values
DT –DEFINE TEN BYTES
Used to tell assembler to define a variable which is 10 bytes in length or to
reserve 10 bytes of storage in memory
EQU- EQUATE
It is used to assign a label with value or symbol. Every time the assembler finds
the given label in the program, it will replace the label with the value or symbol
we have equated with that label.
Example ADDITION EQU ADD (assigns label ADDITION with mnemonic
ADD)
ORG- ORIGIN
Start the memory allotment for particular segment, block or code from declared
address in ORG statement
Example the statement ORG 3000H - tells the assembler to set the location counter to
3000H
PROC- PROCEDURE
Marks the start of a named procedure in the statement
Example RESULT PROC NEAR
Marks the start of routine RESULT, which is called by program located in same segment of
memory
RESULT PROC FAR
FAR directives, which is called by program located in different segment of memory
ASSUME: Assume Logical Segment Name
 used to inform the name of logical segment to be assumed for different
segments used in the program
Example: Assume CS: CODE – directs the assembler machine codes are
available in segment named CODE, hence CS register is to be initialised by the
segment address value alloted by OS for code segment, while loading.
END- END OF PROGRAM
This directive indicates the assembler that this is the end of assembly language
program . The assembler ignores any statements after an END directive.
Should be the last statement in the file
ENDP -END PROCEDURE
 It indicates the end of the procedure to the assembler. In assembly language
programming, subroutines are called procedure.
EX: PROCEDURE STAR

STAR ENDP
ENDS- END SEGMENT
 This directive indicate the end of the logical segment
EX: ASSUME CS : CODE
CODE SEGEMNT

CODE ENDS
NAME: Logical Name of a module
 used to assign a name to an assembly language program module.
 Module may refer by its declared name
LABEL
Used to assign a name to the current content of location counter
Type of label must be specified (NEAR or FAR, BYTE or WORD)
Example CONTINUE LABEL FAR (can be used for FAR jump, if program contain this statement)
LENGTH: Byte length of label
 Not available in MASM.
Used to refer the length of a data array or string
Example MOV CX, LENGTH ARRAY (substitute the length of array ARRAY in bytes, in
instruction)
• Decide logical segment (segment reg) need for the program
• From the statement of program, can guess whether data required for program
or result of program stored in memory. In that case need data segment.
• Code seg is part of program contain inst. Seq to be executed
• If stack facility is to used, need stack segment
• Extra segment for additional destination data segment
• Note: all logical segments is not compulsory except code segment.
• Assume directive: tells assembler label CODE and DATA is logical name for code
and data segment.
• Second line DATA segment, starting of logical data space DATA
• Inside the DS, declare your data. DB used to reserve byte of memory location for
the variable and to put the above specified value in that memory location when the
program is loaded into RAM.
• Putting actual segment address value into seg reg is seg reg initilaization
• CS is intialized by loader at time of loading the EXE file into memory for execution.
• First two ins. For data seg initialization
DIGITAL LOGIC
AND MICROPROCESSOR

DR.M.SINDHUJA
ASSISTANT PROFESSOR(SENIOR GRADE)
SCHOOL OF ELECTRONICS
VIT, CHENNAI
Assembly language Programming of 8086
ASSEMBLY LANGUAGE PROGRAMMING

• A Program called assembler used to convert mnemonics of instructions along


with data(source file) into equivalent object code (object file).
• These object codes may further converted into machine codes or executable
file using linker
• This type of programming is called Assembly language Programming
• In Assembly language Programming, Mnemonics are directly used in user
programs.
• Assembler perform the task of coding
ASSEMBLY LANGUAGE DEVELOPMENT TOOLS

To develop assembly language program, need program development tools


such as,
 EDITOR - Norton’s Editor(NE.com)
 ASSEMBLER - Microsoft Assembler(MASM.EXE)
 LINKER -(LINK.EXE)
 DEBUGGER -(DEBUG.EXE)
Before start the process, ensure that all the above mentioned file are
available in same directory in which you are working.
ENTERING A PROGRAM - NORTON’S EDITOR
• To start Norton’s Editor, type NE after C and enter the directory.
C > NE
• After pressing the enter key, Norton’s Editor’s opening page will be displayed

• Then type the file name. For example, assume the file name is ABC and it will be
displayed in screen.is
• When any key is pressed, the ABC.ASM file will be opened.

• After that, enter text to edit the assembly-language program. A sample program
ABC.ASM is edited to subtract two numbers as shown in Fig.
• Ifwe want to open a file directly, the command is C>NE ABC.ASM. Then ABC.
ASM file will be opened and displayed on the CRT screen.

• After editing the program or modifying the existing program, the F3-E
command is used to save the program and exit from Norton’s Editor by using the
F3-Q command.
ASSEMBLING A PROGRAM – MASM ASSEMBLER
The Microsoft Assembler MASM is a most popular assembler and it is very easy to use.
Main task of any Assembler is to accept the text assembly language program file
as an input and prepare an object file
 MASM accepts the file names only with extension.ASM
 Example, to assemble the program, enter a following command
C > MASM ABC or C > MASM ABC.ASM
If any of command option is entered as above, screen displays will be
If we enter the Command C > MASM , will be displayed as the opening page of
MASM.

 The source filename should be typed in the source filename with or without
extension the .ASM. Then valid filename will be accepted if the enter key is pressed.
 Enterthe .OBJ file name which creates the object file of the assembly-language
program.
.OBJ file is created with entered name and .OBJ extension.
.OBJ file contain the coded object modules of the program to be assembled
• On next line, a filename is entered for expected listing file of source file.
• The listing file automatically generated in assembly process and it is identified by
.extension.LST.
• Listing file contain total offset map of source file including labels, Offset
addresses, opcodes , Memory allotment for different labels and directives and
relocation information
• The cross-reference filename is also entered in the same way as the listing file and
it is used for debugging the source program.
• The.CRF file contains information such as size of the file in bytes, number of
labels, list of labels, and routines of the source program.
• After entering the cross reference file name, the assembly-language process
starts.the same
• Thensyntax errors of the program are displayed using error code
number and the corresponding line number, if the program has any
syntax errors.
• When the programmer removes all syntax errors, the assembly
process will be completed successfully.
• After successful assembly process, the .OBJ, .LST and .CRF files, are
generated and these files can be linked by the linker programmer to
link the object modules and generate an executable (.EXE) file
LINKING A PROGRAM – LINK
LINK.EXE file link the different object modules of source program and
function library routines to generate executable code of source program.
Input to linker is .OBJ file and it generate .EXE file
The linker program is executed by command
C> LINK or C> LINK ABC.OBJ
DEBUG
DEBUG.COM is a program which allow
programmer to debug and trouble-shoot
assembly language programs
Used to examine the content of register and
memory
Used to execute a program, but one instruction
at a time
The command to start debug is C> DEBUG
The debug command is executed and a hypen(-)
which is known as debug prompt will be
displayed
Any valid command such as –R, -M, -A and –U
is accepted using enter key
DEBUG COMMANDS
COMMANDS FUNCTIONS

-R Display all registers and flags


-D Display contents of specified memory location
-A Assemble from the current CS:IP
-G Go command execute any program
-T Trace command used to run a program in single step mode
-S Search a byte or string of bytes
-Q Quit the debug and return to DOS
-M Move the block of data from one memory block to another
-U Unassemble from the Current CS:IP
DIGITAL LOGIC
AND MICROPROCESSOR

DR.M.SINDHUJA
ASSISTANT PROFESSOR(SENIOR GRADE)
SCHOOL OF ELECTRONICS
VIT, CHENNAI
ASSEMBLY LANGUAGE PROGRAMMING OF 8086
HOW TO WRITE AN ASSEMBLY LANGUAGE PROGRAM
• First step is to define and study the problem
• Decide the logical modules required for program
• From statement of program, may guess some data required for program or result of
program to be stored. Hence program need logical space called Data segment
• Code segment is part of program contain instruction sequence to be executed
• If stack facility to be used, it require stack segment
• Extra segment used for additional destination data segment
• All these Logical segment is not compulsory except Code segment
• Some program need both code and Data segment.
ASSEMBLY LANGUAGE PROGRAMMING OF 8086
EXAMPLE PROGRAM FOR ADDITION OF TWO NUMBERS
PROGRAM EXPLANATION

• First
line of program „Assume‟ directive declares label CODE used as logical
name for CODE segment and label DATA used for DATA segment throughout the
program.
• Second line, DATA segment marks starting of logical data space DATA.
• Inside the data OPR 1 and OPR 2 as word operand of value 1234H and 00002H
• Third, DW directive 01H DUP(?) reserves words of memory for storing result
• DATA ENDS marks end of DATA segment
• Assembler calculate data segment require 6 bytes
• CODE segment containing instructions
• LABEL STARTS marks the starting point of execution sequence
• A Programmer has to initialize DS, SS and ES using instructions, while CS is
automatically initialized by loader at time of loading the EXE file into memory
• First two segment in program are for data segment initialization
• MOV instructions – move two operands OPR 1 and OPR 2 in AX and BX.
• Carry is cleared before addition operation (optional)
• ADD instruction will add BX into AX and store result in AX
• Indexed addressing mode used to store result of addition in memory location
labeled RESULT
• MOV DI, OFFSET RESULT ; stores the offset of label RSEULT into DI register
• Next instruction store the result available in AX into address pointed to by DI
• Function value 4CH for returning to DOS prompt
• CODE ENDS marks the end of CODE segment
EXECUTION OF PROGRAM
• Assemble the above written program using MASM after entering into computer using editor.
• Once you get EXE file as output of LINK program, listing is ready for execution
• If prepared program file in form of KMB.EXE in directory
• Execute with the command C> KMB
• This method of execution will store result of program but not display on screen
• To display on screen, programmer have to use DOS function call which make program too
lengthy
• Another method to check result is DEBUG
• To run program under DEBUG and to observe results, one must prepare LST file.
• LST file can displayed using Norton’s editor
DISPLAY THE MESSAGE “ THE STUDY OF MICROPROCESSOR IS INTERESTING”
ON THE CRT SCREEN OF A MICROCOMPUTER

You might also like