Professional Documents
Culture Documents
Module 7 Merged
Module 7 Merged
AND MICROPROCESSOR
DR.M.SINDHUJA
ASSISTANT PROFESSOR(SENIOR GRADE)
SCHOOL OF ELECTRONICS
VIT, CHENNAI
MODULE -7
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
• 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
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