390 likes | 497 Views
COURSE OUTCOMES OF MICROPROCESSOR AND PROGRAMMING. Visit for more Learning Resources. THE ART OF ASSEMBLY LANGUAGE PROGRAMMING. CHAPTER 4. Program development steps. Defining the problem Algorithm Flowchart Initialization checklist Choosing instruction
E N D
COURSE OUTCOMES OF MICROPROCESSOR AND PROGRAMMING Visit for more Learning Resources
THE ART OF ASSEMBLY LANGUAGE PROGRAMMING CHAPTER 4
Program development steps • Defining the problem • Algorithm • Flowchart • Initialization checklist • Choosing instruction • Converting algorithm to assembly language program
Defining the problem • The first steps in writing program is to think very carefully about the problem that you want to solve. • The problem is given in the form of statement or mathematical expression • Read the problem carefully and understand the problem • Expand the problem to get a clear ,concise and accurate description • E.g: read temperature from sensor
Algorithm • An algorithm is a step-by-step instruction require to solve any problem. • An algorithm consist of a set of explicit , finite steps which when carried out for a given set of initial condition,produce the output.
Flowchart • The flowchart is graphically representation of the program operation • The specific operation is represented by graphical symbol such as circle ,rectangle , diagonal, square, parallelogram.
Initialization checklist • In program there are many variables, constant ,and various part of the system such as segment registers ,flags ,stack , programmable port which must be initialize properly. • The best way to approach the initialization task is to make the checklist of the entire variables, constants, registers , flags &ports
Choosing instructions • Next steps is to choose proper instruction that performs your problem’s operation • This is an important step that breaking down the programming problems sequences of steps easy to find the instruction solve the problem
Converting algorithm into assembly language • In assembly language program a first step is to set up & declare the data structure that the algorithm will be working with then write down the instruction required for initialization at the start of the code section. • Determine the instruction required to implement the major actions in the algorithm
Assembly language program development tools 1)Editor: • An editor is a program which helps you to construct your assembly language program in right format- translate it correctly in machine language • So you can type your program using editor • Form of the program source program. • DOS based editor such as EDIT ,wordstar &norton editor
Assembler • An assembly is a program that translate the program-into binary code for each instruction .i.e: machine code and generate the file called as object file with extension .obj • Example: tasm ,masm
Linker • A linker is a program which combines if requested more than one separately assembled module into one executable program • Example: Tlink
Debugger • Debugger is a program that allows the execution of program in single step mode under the control of the user. • The process of locating & correcting errors using a debugger is known as debugging • Example: DOS debug command , borland’s turbo debugger.
Program development process • Source file creation • Object code generation • Executable file creation • Program running • Program testing • Program debugging
Data definition direction 1) DB • The directive DB to define a byte type variable • It can be used to single or multiple byte variable. • The range of values that can be stored in a byte is 0 to 255 for unsigned number & -128 to +127 for signed numbers • Name_of_variable DB initalization_value(s)
Dw: define word • The directive Dw to define a word type • It can be used to define single or multiple word variables • The range is 0 to 65535 for unsigned numbers & -32768 to +32767 • General form: Name of variable DW initialization value(,s)
DD: define double word • DD used to define a double word type • Can be used to define single or multiple double word variable i.e 4 byte • Range is 0 to 2^32-1 for unsigned numbers • -2^32-1 to 2^32-1-1for signed numbers • General form: Name_of_variable DD Initalization_value(,s) Example: NUM DD ?=allocate four memory locations
DQ: define quad word • DQ is used to define a quad word type • It can be used to define single or multiple quad word variable • Range is 0 to 2^64-1 for unsigned numbers • -2^64-1 to 2^64-1-1 for signed numbers • It is used in the math coprocessor instruction where large no are used in computation • General form: Name_of _variable DQ initalization_value(,s) Example: NUM DQ ? = allocate 8 memory location
DT: define ten byte • DT: used to define a ten byte type variable • Can be used to define a single or multiple 10 byte variable. • Range 0 to 2^80-1 for unsigned number • -2^80-1 to 2^80-1-1 for signed integer numbers • The floating point numbers range from 10^-4932 to 10^4932 • The DT type variables useful in math coprocessor instruction where large numbers are used in computation
-General form: • Name_Of _ variable DT Initalization_Value( , s) • Example: • NUM DT ? = allocate ten memory locations • TABLE DT 1,2,3,564,5689 = allocate fifty memory location -
LABEL • The directive LABEL enables you to redefine the attribute of a data variable or instruction label. • General form: Variable_name LABEL type_specifier Example: • TEMP LABEL BYTE • NUM LABEL WORD
ALIGN : alignment of memory address • The directive ALIGN - to force the assembler to align the next data item • General form: ALIGN Numeric_value -the number must be a power of 2 such as 2 ,4 ,8 ,16 Example: ALIGN 4
STRUCT: structure declaration • STRUCT - to declare the data type which is primary collection of data type • Structure declaration allows the user to define a variable which has more thatn one data type. • General form: Structure _name STRUCT …………. ; sequence of DW ,DD directives for declaring ; ; field ………… structure_name ENDS • Example: Employee STRUCT emp_num DW ? emp_name DB 25 DUP(0) emp_dept DB 30 DUP (0) Employee ends
Accessing structure variable field: • - The structure variable field can be accessed by using a dot(.) operator known as the structure access operator. • General form: • Structure_variable. Field _name • Example: • here structure variable name is emp1 • emp1.emp_num • emp1. emp_name • emp1.emp_dept
EQU:equate to • The EQU directive declare the symbols which some constant value is assigned. • Such symbolscalled as macro symbols • Macro assembler will replace every occurrences of the symbols • Macro increase readability of program • General form: symbols_name EQU Expression Example: NUM EQU 100
ORG: originate • ORGassign the location counter with the value specified in the directive • Helps in placing the machine code in the specified location while translating the instruction into machine codes by the assembler. • This feature useful in buliding device drivers • General form: ORG [$] Numeric_value Example: ORG 100h
Program organization directives 1) ASSUME : • Assume informs the assembler the name of the logical segment that should be used for a specified segment. • General form: ASSUME seg_reg: Seg_name,……………..seg_reg:Reg_name Where ASSUME is a assmebler directive Seg_reg is any of the segment register Seg_name is the name of an user defined segment Example: ASSUME CS: code segment, DS: data segment
SEGMENT • Segment is used to indicate the beginning of the logical segment. • Segment follows the name of the segment • Segment &ends must be enclosed the segment data, code ,extra or stack of the program. • General form: segment_name SEGMENT [WORD /PUBLIC] • WORD indicates that the segment has to be located at the next available address. • PUBLIC indicates that the given segment which have the same name.
Example: code segment ……………… ………………. code ends Data segment ………………. ……………… Data endsaa
ENDS:end of the segment • ENDS informs the assembler the end of the segment • ENDS & SEGMENTmust enclosed the segment data or code of the program. • General form: segment_name ENDS Example: my_data segment ……….. My_data ENDS
END:end of the program • END to inform assembler the end of the program. • General form: END[start_address] • start_address indicates the location in the code segment where execution is to begin.
.CODE:simplified CODE segment directive • This simplified segment directive defines the code segment. • All executable code must be placed in this segment. • General form: .CODE [name]
.DATA:simplified DATA segment directive • This simplified segment directive defines the data segment for initialized near data • All data definition & decalration must be placed in this segment. • General form: .DATA
.STACK : simplified STACK segment directive • It defines the stack segment & default size of the stack is 1024 bytes which you may override. • General form: .STACK 100
.MODEL: memory model decalration for segment • It creates default segment. • General form: .MODEL memory_small Memory model: • TINY=masm 6.0 used for .com program • SMALL= all data in one segmetn & all code in one segment. • LARGE=both data &code in more than one segment
Value returning attribute directives 1) LENGTH: • The Lengthinforms the assemblers about the number of the elements in a data items such as array • If the array is defined in DB it return number of bytes allocated to a variable. • It the array is defined in DW it return the number of word allocated to the array variable.
General form: LENGTH variable_name Example: MOV CX,LENGTH NAME
SIZE • It is same as LENGTH except that it return the number of bytes allocated to the data items instead of the number of element in it • General form: SIZE variable_name Example: MOV AX, SIZE NAME
SEG:segment • The SEG is used to determine the segment in which the specified data items is defined • General form: SEG variable_name Example: MOV DS,SEG MSG For more detail contact us