Q. State and Explain steps involved in program development. [w-08, w-10, s-12, w-11] Answer: 1. Defining Problem 2. Algorithm 3. Flowchart 4. Initialization of checklist 5. Choosing instructions 6. Converting algorithm into program. Q. what is algorithm? What is flowchart? Sketch symbols of flowchart. Answer: [refer techmax] Q. Explain Assembler, linker, editor, debugger. [Most important questions. Always ask in exam] Answer:[Refer manual and Techmax] Assembler directives: [note: all the directives are important. But concentrate on those directives which are given in important questions] Assembler directives help the assembler to correctly understand the assembly language programs to prepare the machine codes. Assembly language programs are composed of two types of statements: i) The instructions, which are translated to machine code by the assembler. ii) The directives that direct the assembler during the assembly process, for which no machine code is generated. Directive is a statement which gives direction to the assembler. The directives are also called pseudo instructions and are not translated into machine language. The directives are necessary for the assembler to assemble efficiently and correctly.
2.1.1. Data Definition and Storage Allocation Directives: Data definition directives are used to define the program variables and allocate a specified amount of memory to them. a) DB: Define Byte: The DB directive is used to reserve byte or bytes of memory locations in the available memory. Name of the variable DB Initialization Value i) RANKS DB 01H, 02H, 03H, 04H This statement direct the assembler to reserve four memory locations for a list named RANKS and initializes them with the above specified four values. ii) MESSAGE DB GOOD MORNING This makes the assembler to reserve the number of bytes of memory equal to the number of characters in the string names MESSAGE and initialize those locations by the ASCII equivalent of these characters. b) DW: Define Word: The DW directive serves the same purposes as the DB directive, but it now makes the assembler the number of memory words (16-bit) instead of bytes. Name of the variable DW Initialization Value
i) WORDS DW 1234H, 4567H, 78AH, 045CH This makes the assembler to reserve four words in memory (8 bytes), and initialize the words with the specified values in the statements. During the initialization, the lower bytes are stored in the lower memory addresses, which the upper bytes are stored in the higher addresses. Another option of the DW directive is explained with the DUP operator. ii) WDATA DW 5 DUP (6666H) This statement reserves five words, i.e., 10-bytes of memory for a word label WDATA and initializes all the word locations with 6666H. c) DQ: Define Quad word: This directive is used to direct the assembler to reserve 4 words (8 bytes) of memory for the specified variable and may initialize it with the specified values. Name of the variable DQ Initialization Value TOTAL DQ 0 Reserves 8 bytes of memory for the variable TOTAL and initializes with 0. d) DD: Define Double: The directive DD is used to define a double word (4 bytes) variable. Name of the variable DD Initialization value
TOTAL DD 0 Reserves 4 bytes of memory for the variable TOTAL and initializes with 0. e) DT: Define Ten bytes: Name of the variable DT Initialization Value The DT directive directs the assembler to define the specified variable requiring 10 bytes for its storage and initialize the 10 bytes with the specified values. ACODE DT 0 The above statement informs the assembler to reserve 10 bytes of memory for a variable named ACODE and initialize with 0. 2.1.2. STRUCTURE DECLARATION: STRUCT: The directive strut is used to declare the data types, which is a collection of programming primary data types, i.e., DB, DW, DT, DT and DQ. Structurename Strut : : : Sequence of DB, DW, DQ, DD for declaration fields :
: Structurename ENDS Student Strut Roll-no DW? Name DW 10 DUP (?) Class DB? Branch DB 10 DUP (?) Student ENDS 2.1.3. PROGRAM ORGANIZATION DIRECTIVES: The 8086 programs are organized as a collection of logical segments. The directives used to organize the program segments are: SEGMENT, ASSUME, ENDS etc. a) SEGMENT: The directive SEGMENT is used to indicate the beginning of a logical segment. The directive segment follows the name of the segment. To end the segment, SEGMENT must be ended with ENDS statement. DATA SEGMENT program data definition
DATA ENDS b) ENDS: The directive ENDS informs the assembler the end of the segment. The directives ENDS and SEGMENT must enclose the segment data or code of the program. Segmentname ENDS. c) ASSUME: The directive assume informs the assembler the name of the logical segment that should be used for a specified segment when program is loaded and the processor segment registers should point to the respective logical segments. ASSUME segreg : segname,.., segreg : segname. i) ASSUME CS : _code ii) ASSUME CS : _code, DS : _Data, SS : _stack 2.1.4. END: End of program: Program termination directive and it is used to inform the assembler the physical end of the program. The statement after the directive END will be ignored by the assembler. 2.1.5. VALUE RETURNING ATTRIBUTE DIRECTIVES: The task of programming can be made easier by assigning assembler to compute the size of the data items it is performed using the directives LENGTH, SIZE, OFFSET and TYPE. a) LENGTH: The directive LENGTH informs the assembler about the number of elements in a data item such as an array. If an array is defined with DB then it returns the number of bytes
allocated to a variable. If an array is defined with DW then it returns the number of words allocated to the array variable. LENGTH Variablename DATA Segment Name DB 100 dup (?) A DW 50 dup (?) Total DW? DATA ENDS AX, LENGTH Name then AX = 100 bytes i.e., array size BX, LENGTH A then BX = 50 words i.e., array size. b) SIZE: The directive size is same as length except that it returns the number of bytes allocated to the data item instead of the number of elements in it. SIZE variablename DATA Segment Name DB 100 DUP (?) A DW 50 DUP (?) TOTAL DW? DATA ENDS AX, Size Name
then AX= 100 bytes i.e., array size. BX, Size A then BX= 100 bytes i.e., array size CX, Size TOTAL then CX= 2 bytes c) OFFSET: The directive OFFSET informs the assembler to determine the displacement of the specified variable with respect to the base of the segment. It is usually used to load the offset of a variable into the register using this OFFSET value a variable can be referenced using indexed addressing modes. OFFSET VariableName DATA Segment MSG DB Hello World A DW 50 DUP (?) DATA ENDS DX, OFFSET MSG DX= offset of the variable MSG SI, OFFSET A SI= offset of the array. AX, [SI] AX= element of array pointed to by SI i.e.[si] refers to A[1] [SI+2] refers to A[2]
[SI+4] refers to A[3] d) SEG: SEGMENT: The directive SEG is used to determine the segment in which specified data item is defined. SEG VariableName DATA Segment MSG DB Hello World A DW 50 DUP (?) DATA ENDS DS, SEG MSG DS= segment in which the variable MSG exists DS, SEG A DS= segment in which array A exists. e) TYPE: The directive type is used to determine the type of data type. The assembler allocates one byte to DB. Two bytes to DW and 4 bytes to DD. TYPE Variable name DATA Segment MSG DB A A DW 100 PI DD 3.17 DATA ENDS
ADD BX, TYPE MSG (MSG is DB type) ADD BX, TYPE A (A is DW type) ADD BX, TYPE PI (PI is DD type) 2.1.6. Procedure Definition Directives: The procedure definition directives are used to define subroutines. a) PROC: Procedure: The directive PROC indicates the beginning of the procedure. The directive PROC follows the name of the procedure and the term NEAR or FAR follows the PROC indicating the type of procedure. The directive PROC is used with the directive ENDP to enclose the procedure code. Procedure Name PROC NEAR/FAR ONE PROC NEAR TWO PROC FAR Readint PROC Write procedure code to read integer data
Readint ENDP b) ENDP: End of Procedure: The directive ENDP informs the assembler the end of procedure. Procedure Name ENDP ONE1 ENDP. 2.1.7. Macro Definition Directives: These are used to define macro constants and macro functions. a) EQU: Equate Macro Constant: The directive EQU is used to declare the symbols to which some constant value is assigned such symbols are called as macro symbols and macro assembler will replace every occurrence of the symbol in a program by its value. Macros are used to increase the readability of a program. The advantage of macro is that the modification of the symbol value of the declaration will be reflected throughout the program. Num EQU 100 H AX, Num AX, 100 H b) MACRO: The directive macro informs the assembler the beginning of a macro. It consists of name of the macro followed by a keyword MACRO and macro arguments if any. The directive MACRO and ENDM must enclose the definition, declarations or a small part of the code which have to be substituted at the innocation of a macro. Macroname MACRO (arg1, arg2,, argn)
Printstring MACRO MSG INT AH, 09 H DX, OFFSET MSG 21 H ENDM 2.1.8. Data Control Directives: The data control directives are used to declare the variables used in communication of information between the program modules. a) PUBLIC: The directive PUBLIC informs the assembler that the specified variable of segment can be accessed from other program modules. It helps in managing multiple program modules by sharing global variables (or) procedure. The variables and procedures to be shared must be declared as public in a module in which physically exists. PUBLIC variable 1, variable 2,., variable n PUBLIC XMAX, YMAX. The variables XMAX, YMAX can be accessed from other program modules by declaring them as external using the directive EXTRN. b) EXTRN: External: The directive EXTRN informs the assembler that the data items are labeled following the directive will be used in a program module which is defined in another program module. EXTRN XMAX, YMAX : WORD EXTRN EXTRN Myprint : FAR FACT : NEAR
c) PTR: Pointer: The pointer operator is used to declare the type of a label, variable or memory operand. The operator PTR is prefixed by either BYTE or WORD. If the prefix is BYTE, then the particular label, variable or memory operand is treated as an 8-bit quantity, while if WORD is prefix, then it is treated as a 16-bit quantity. In other words, the PTR operator is used to specify the data type byte or word. i) AL, BYTE PTR [SI] Moves content of memory location addressed by SI (8-bit) to AL. ii) INC BYTE PTR [BX] Increment byte contents of memory location addressed by BX.