Download Ans: Assembler Directives

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Chapter 4
Q. State the function of “Assembler”.
(2M for function)
Ans.: Assembler is a program that translate assembly language program to the correct binary
code
for each instruction.
Q. State the steps involved in ALP using procedure.
Ans.: Step involved in ALP: (2 Mark)
1. Defining the problem
2. Algorithm
3. Flowchart
4. Initialization of checklist
5. Choosing instructions
6. Converting algorithms to assembly language program
OR
procedure, but before it goes to the subroutine, it saves the returning address on the top of the
stack.
set of next instruction after the
CALL on the stack.
instruction at the end of the procedure. This done by popping up the offset saved on the stack
back to IP
Q. What is an algorithm? What is a Flow chart? Sketch any four symbols used in flow
chart.
Ans.: i) Algorithm: Algorithm is a task or sequence of operations perform by program can be
specified as a step called as algorithm. (1 Mark)
ii) Flow chart is a graphical representation of task. (1 Mark)
iii) Symbols: (2 Mark)
Process ,Input /Output ,Connecter ,Decision ,Sub-routine ,Termination
Q. List any four assembler directives and explain any two of them.
(Any other assembler directives written by students can be considered)
Page No.1
Chapter 4
(Students may also write directives from segment define directives, segment combine
directives and processor directives)
(Listing of any four 2 marks, Explanation of any two 1 M each)
Ans.: Assembler directives are: 1) DB 2) DW 3) DQ 4) DT 5) ? (Uninitialized value)
6) PTR 7) OFFSET 8)EQU 9) DUP 10) LABEL 11)ALIGN 12) EVEN 13) ORG 14) DOSSEG
15) STRUCT 16) DD
1) DB: Define byte (8 -bit)
The db directive is used to reserve byte or bytes of memory locations in the available memory.
2) DW: Define word (16-bits)
The dw directive is used to reserve the memory words instead of bytes.
Q. State functions of following assembly language programming tool.
(i) Assembler
(ii) Linker (Any two functions of each : 2 Marks)
i) Assembler
1. Assembler is a program that translates assembly language program to the correct binary code.
2. It also generates the file called as object file with extension .obj.
3. It also displays syntax errors in the program, if any.
4. It can be also be used to produce list(.lst) and .crf files
ii) Linker
a) It is a programming tool used to convert Object code into executable program.
b) It combines ,if requested ,more than one separated assembled modules into one executable
module such as two or more assembly programs or an assembly language with C program.
c) It generates .EXE module
Q. Describe following assembler directives.
(i) DB (ii) ASSUME (iii) SEGMENT (iv) EQU ( For each Directive – 2Mark)
ANS:
i. DB: - Define byte
This directive is used to define a byte type variable.
It can be used to single or multiple byte variable.
The range of byte store is from 0 to 255 for unsigned number and -128 to + 127 for signed numbers.
GENERAL FORM:
NAME_OF_VARIABLE DB INITIALIZE_VALUE(S)
E.g. Num1 DB 36H
ii) ASSUME :
Assume directive is used to tell Assembler the name of the logical segment it should use for
the specified segment.
When program is loaded, the processor segment register should point to the respective logical
segments.
GENERAL FORM:
ASSUME Seg_reg: Seg-name,………,Seg_reg:Seg_name
Where,
ASSUME is a assembler directive.
Seg_reg is any of the segments register i.e CS, DS, ES, SS.
Seg-name is the name of a user defined segment and must be any valid symbol except
reserved keywords.
Example:-Assume CS: MSBTE_CODE, DS: MSBTE_DATA
Page No.2
Chapter 4
iii) SEGMENT:
The directive SEGMENT is used to indicate the beginning of the logical segment.
The directive SEGMENT follows the name of the segment.
The directive SEGMENT and ENDS must be enclosed the segment data, code, extra or stack
of program.
GENERAL FORM:
Segment-name SEGMENT [word/public]
Examples:
My_data SEGMENT
…………….
Program data definition here
My_data ENDS
iv) EQU: Equate to
The EQU directive is used to declare the symbols to which some constant value is assigned.
GENERAL FORM:
Symbol-name EQU expression
Examples:
Num EQU 100
Increment EQU INC
Q. Define flowchart and algorithm.
Ans: (Correct Definition: 1 Mark each)
Flowchart:
flowchart is a graphically representation of the program operation or task.
Algorithm:
formula or sequence of operations to be performed by the program can be
specified as a step in general. English is called algorithm.
Q. State the function of linker and assembler.
Ans: (Any ONE correct function of each: 2 Marks)
Linker: It is a programming tool used to convert Object code into executable program
called .EXE module.
one
executable module such as two or more assembly programs or an assembly language
with C program.
Page No.3
Chapter 4
Assembler: Assembler is a program that translates assembly language program to the
correct binary code for each instruction i.e. machine code and generate the file called as
object file with extension .obj .
n the program, if any.
statements, binary codes, and offset address for each instruction.
Q. Explain the following assembler directive.
(1) ORG
(2) EQU
(3) DD
(4) ASSUME
Ans: (Explanation of each : 1 Mark)
1) ORG : Originate
The directive ORG assigns the location counter with value specified in the directive. It
helps in placing the machine code in the specified location while translating instructions
into machine codes by the assembler. $ is used to indicate current value of location
counter
Syntax: ORG [$+] Numeric_value
Example: ORG 2000H ; set location counter to 2000H
ORG $+100 ; increment value of location counter by 100 from its current.
2) EQU :Equate to
The EQU directive is used to declare the micro symbols to which some constant value is
assigned. Micro assembler will replace every occurrence of the symbol in a program by
its value.
Syntax: Symbol_name EQU expression
Example: CORRECTION_FACTOR EQU 100
Page No.4
Chapter 4
3) DD: -Define Double word (32-bits)
It is used to declare a variable of type double word or to reserve memory locations
which can be accessed as type double word(32-bits)
Example: NUMBER DD 12345678H ; Reserve 2 words in memory.
4) ASSUME: - Assume directive is used to tell Assembler the name of the logical
segment it should use for the specified segment.
Example: Assume CS: MAP_CODE, DS: MAP_DATA
Define flowchart & algorithm.
(For each definition – 1 Mark)
Ans: Algorithm: Algorithm is a task or sequence of operations performed by program.
Flowchart: Flow chart is a graphical representation of task or algorithm.
Attempt any TWO of the following: 8
(i) State the function of
(a) Editor
(b) Assembler
(Each - 2 Marks)
Ans: Editor
It is a program which helps to construct assembly language program with a file extension .asm,
in right format so that the assembler will translate it to machine language. It enables one to
create, edit, save, copy and make modification in source file.
Assembler
Assembler is a program that translates assembly language program to the correct binary code for
each instruction i.e. machine code and generate the file called as object file with extension .obj
List any four assembler directives. State the functions of any two assembler directives.
(Listing of any four - 2 Marks, Explanation of any two - 1 Mark each)
[Note: Students may also write directives from segment define directives and processor
directives]
Ans: Assembler directives are: 1) DB 2) DW 3) DQ 4) DT 5)? (Uninitialized value)
6) PTR 7) OFFSET 8) EQU 9) DUP 10) LABEL 11) ALIGN 12) EVEN 13) ORG
14) DOSSEG 15) STRUCT 16) DD
DB (Define Byte or Data Byte)
• This is used to define a byte type variable.
• The range of values : 0 – 255 for unsigned numbers
-128 to 127 for signed numbers
• This can be used to define a single byte or multiple bytes
DW (Define Word or Data Word)
• This is used to define a word (16-bit) type variable.
Page No.5
Chapter 4
• The range of values : 0 – 65535 for unsigned numbers
-32768 to 32767 for signed numbers
• This can be used to define a single word or multiple words
DD (Define Double Word or Data Double Word)
• This is used to define a double word (32-bit) type variable.
• The range of values : 0 – 232 - 1 bits for unsigned numbers
-232-1 to 232-1 - 1for signed numbers
• This can be used to define a single double word or multiple double word
EQU( Equate To)
• This is used to declare symbols to which some constant value is assigned
• The label assigned using this directive is used throught the program instead of the numeric
value.
• While assembling, whenever the assembler comes across the label, it substitutes the numeric
value for that label.
• Use of EQU is realised when the value of the symbol changes. The single modification in the
EQU directive will make the necessary changes at all places in the program.
EVEN
• The assembler while starting the assembling operation for any program, initialises a location
counter and goes on updating it, as the assembly progresses.
• It assigns addresses to program variables, constants and modules as per requirements
• EVEN directive can be used to reassign the addresses to these variables or constants with
Even address, if it was not so before.
• If location counter is already at the even address, no change is done by the assembler.
LABEL
• This enables the user to redefine the attribute of a data variable or instruction label.
ASSUME
• This informs the assembler the name of the logical segment which should be used for a
specified segment.
• The segment registers are pointed to the various logical segments using this directive.
SEGMENT
• This is used to indicate the beginning of the logical segment.
• The directives SEGMENT, ENDS are always enclosed in data, code, stack and extra
segments.
• In some cases, the segments may be assigned a type like PUBLIC (used by other modules of
the program while linking) or GLOBAL (can be accessed by any other module).
ENDS :
• This directive informs the assembler the end of the segment
• The directives SEGMENT, ENDS are always enclosed in data, code, stack and extra
segments.
• Whatever are the contents of the segments, they should appear in the program before ENDS.
• Any statement appearing after ENDS will be neglected from the segment.
LENGTH
• This is used to refer to the length of a data array or a string.
OFFSET
• This operator first computes the 16 bit displacement of the particular label.
• Then it replaces the string “OFFSET LABEL by the computed displacement.
• This operator is used with Arrays, strings, labels and procedures to decide their default
segment offsets.
• It is usually used to load a offset of a variable into the register
Page No.6
Chapter 4
SEG
• Used to decide the segment address of the label, variable, or procedure and substitutes the
segment base address in place of “SEG” label.
TYPE
• This directs the assembler to decide the data type of the specified label and replaces the TYPE
Label by the decided data type
• For Byte type variable, data type is 1
• For Word type variable, data type is 2
• For Double word type variable, data type is 4
Q . State the steps involved in program development.
(Correct steps : 4 Marks)
Ans:
1. Defining the problem: The first step in writing program is to think very carefully
about the problem that the program must solve.
2. Algorithm: The formula or sequence of operations to be performed by the program
can be specified as a step in general English is called algorithm.
3. Flowchart: The flowchart is a graphically representation of the program operation or
task.
4. Initialization checklist: Initialization task is to make the checklist of entire variables,
constants, all the registers, flags and programmable ports
5. Choosing instructions: Choose those instructions that make program smaller in size
and more importantly efficient in execution.
6. Converting algorithms to assembly language program: Every step in the algorithm
is converted into program statement using correct and efficient instructions or group of
instructions.
Q. State the functions of –
(i) Editor (ii) Assembler (Any 2 Functions of each - 2 Marks)
Ans:
(i) Editor
1. It is a program which helps to construct assembly language program with a file
extension .asm, in right format so that the assembler will translate it to machine
language.
2. It enables one to create, edit, save, copy and make modification in source file.
(ii) Assembler
1.Assembler is a program that translates assembly language program to the correct binary
code.
2.It also generates the file called as object file with extension .obj.
3.It also displays syntax errors in the program, if any.
4.It can be also be used to produce list(.lst) and .crf files
Q. What are assembler directives? Explain any two assemble directives.
(Assembler Directives - 1 Mark, Explanation of any two - 1½ Mark each; Any other
directives can
also considered)
Page No.7
Chapter 4
Ans: Assembler Directives: Assembly language program supports a number of reserved
words i.e keywords that enables the assembler to control the way in which a program
assembles and lists. Assembler directives are the statements that give direction to the
assembler and also called as pseudo instructions that are not translated into machine code.
1) DB :Define byte(8 bits)
It is used to declare a byte type variable of 8 bit. It also can be used to declare an array of
bytes. The range of values that can be stored in a byte is 0 to 255 for unsigned numbers
and -128 to +127 for unsigned numbers.
e.g
NUM DB ? ; Allocate one memory location
ARRAY DB 12,25,26,55,65 ; Allocate five memory locations
2) DW: -Define Word (16-bits)
It is used to tell the assembler to define a variable of type word in memory or to reserve
storage locations of type word (16) in memory.
e.g. BLOCK DW 1234H, 3456H, 5678H : Declare array of 3 words.
3) DD: -Define Double word (32-bits)
It is used to declare a variable of type double word or to reserve memory locations which
can be accessed as type double word(32-bits.)
e.g. NUMBER DD 1,2,3,4,9 ; allocated 20 memory locations.
4) DQ : Define Quad Word(4 words)
This directive is used to tell the assembler to declare a variable 4 words in length or to
reserve 4 words of storage
NUM DQ ? ;Allocate 8 memory locations
5)DT :Define Ten byte .This directive is used to tell the assembler to define a variable
which is 10 bytes in length or to reserve 10 bytes of storage in memory.
NUM DT ? ; Allocate Ten memory locations;
6)EQU :Equate to
The EQU directive is used to declare the micro symbols to which some constant value is
assigned. Micro assembler will replace every occurrence of the symbol in a program by
its value.
Syntax: Symbol_name EQU expression
e.g CORRECTION_FACTOR EQU 100
7) ORG : Originate
The directive ORG assigns the location counter with value specified in the directive. It
helps in placing the machine code in the specified location while translating instructions
into machine codes by the assembler. $ is used to indicate current value of location
counter
Syntax: ORG [$+] Numeric_value
e.g ORG 2000H ; set location counter to 2000H
ORG $+ 100 ; increment value of location counter by 100 from its current.
8) ALIGN : Alignment of memory addresses
This directive is used to force the assembler to align the next data item or instruction
according to given value.
Syntax: ALIGN Numeric_value
e.g ALIGN 4 ;advances location counter to the next address that is evenly divisible by 4
Page No.8
Chapter 4
9) EVEN: - The directive even is used to tell assembler to increment the location counter
to the next even memory address.If the location counter is already pointing to even
address it should not be increment.
Example: - DATA SEGMENT
Array DB 9 DUP (?)
EVEN
Block DW 100H DUP (0)
DATA ENDS
10) LABEL:
The LABEL directive is used to give a name to the current value in the location counter
.IT enables you to redefine the attributes of a data variable or instruction label.
Syntax: variable_name LABEL type_specifier
e.g STACK_TOP LABEL WORD
TEMP LABEL BYTE
11) DUP: Duplicate memory location
This directive can be used to generate multiple bytes or words with known as well as uninitialized values.
e.g TABLE DW 100 DUP(0) ; Create array of 100 words all contains data 0
12) ASSUME: - Assume directive is used to tell Assembler the name of the logical
segment it should use for the specified segment. When program is loaded the processor
segment register should point to the respective logical segments.
Example: - Assume CS: MSBTE_CODE, DS: MSBTE_DATA
13) SEGMENT: Used to indicate the beginning of logical segment. Preceding the
SEGMENT directive is the name of the given segment
Syntax:
Segment_Name SEGMENT [Word/Public]
e.g My_data SEGMENT
---My_data ENDS
14) ENDS : End of segment .The directive ENDS is used with the name of a segment to
indicate the end of that logical segment (which contains instructions or data).
CODE SEGMENT ;Start of logical segment
------ ;Instruction statements
CODE ENDS ;End of segment named CODE.
15) END: End of Program
This directive is used to inform assembler the end of the program. The assembler will
ignore any statements after an END directive.
16) Length : The directive length determines the number of elements in some named
data item, such as a string or an array
Syntax: LENGTH Variable_Name
MOV CX,Length Array ; Find no of elements in Array and load length to CX.
17) Size: This directive returns the number of bytes allocated to the data item instead of
number of elements in it
Syntax: SIZE Variable_name
Example : MOV AX, SIZE Total ; Find no of bytes in Total and load length to CX.
Page No.9
Chapter 4
18) OFFSET: This directive tells the assembler to determine the offset or displacement
of a named data item or procedure from the start of segment which contains it. Used to
load the offset of variable into a register so that variable can be accessed with one of the
indexed addressing mode.
Syntax : OFFSET Variable_name
Ex OFFSET BX,PRICES ;determine the offset of variable PRICES from seg start
and load
displacement in BX
Page No.10