0% found this document useful (0 votes)
4 views38 pages

8086 Addressing Modes & Instructions

Uploaded by

prajitha850
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views38 pages

8086 Addressing Modes & Instructions

Uploaded by

prajitha850
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Syllabus- Module 2 2

MODULE 2
Addressing modes and Instructions
 Addressing Modes of 8086 o Flag manipulation & Processor control
instructions.
 Instruction set
 Assembler Directives and operators.
o Data copy /transfer instructions
o Arithmetic instructions  Assembly Language Programming
with 8086.
o Logical instructions
o String manipulation instructions
o Branch instructions
CST 307 : Microprocessors &
• Unconditional and conditional branch
Microcontrollers instruction

Addressing Modes 5
Addressing Modes 6
Control Transfer Instructions
 Addressing mode indicates a way of locating data or operands. 1. Immediate Depend upon whether the destination location is within
 Addressing modes describe the types of operands and the way they are accessed for the same segment or in a different one
2. Direct
executing an instruction.
Intersegment mode- Destination location lies in a different segment.
 According to the flow of instruction execution, the instructions may be categorised as
3. Register
Intra-segment mode-Destination location lies in the same segment
o Sequential control flow instructions :After execution, transfer control to the next instruction 4. Register Indirect
9. Intra-segment Direct Mode
appearing immediately after it (in the sequence) in the program.
5. Indexed
-For example, the arithmetic, logical, data transfer and processor control instructions are sequential control flow 10. Intra-segment Indirect Mode
instructions. 6. Register Relative
11. Intersegment Direct
o Control transfer instructions: Transfer control to some predefined address or the address somehow
specified in the instruction, after their execution.
7. Based Indexed
12. Intersegment Indirect
-For example, INT, CALL, RET and JMP instructions fall under this category. 8. Relative Based Indexed
Instruction Format 7
1. Immediate 8

1. Operation Destination, Source  Immediate data is a part of instruction


Opcode Operand, Operand
o Appears in the form of successive byte or bytes.

2. Operation Source
Opcode Operand
o In the above example 0005H and 06H are the immediate data.

3. Operation • The immediate data may be 8-bit or 16-bit in size

Opcode

2. Direct 9
3. Register 10

 a 16-bit memory address (offset) or an IO address is directly specified in the


 The data is stored in a register and it is referred using the
instruction as a part of it.
particular register.
o All the registers, except IP, may be used in this mode.
 Here, data resides in a memory location in the data segment, 5000H as the offset
o The effective address may be computed using offset address and content of DS as segment
address.

o The effective address (EA), here, is 10H*DS+5000H.


o The operands in these instructions are provided in registers BX, AX and
 In the second instruction 80H is IO address.
AL, BL respectively.
4. Register Indirect 11
5. Indexed 12

 The address of the memory location (which contains data or operand) is


 A special case of register indirect addressing mode
determined in an indirect way, using the offset registers.
 Offset of the operand is stored in one of the index registers.
o The offset address of data is in either BX or SI or DI register.
o DS is the default segment for index registers SI and DI.
o The data is supposed to be available at the address pointed to by the content of any of
the above registers in the default data segment. • In case of string instructions DS and ES are default segments for SI and DI respectively.

o The default segment is either DS or ES.

o Data is available at an offset address stored in SI in DS.

o Here, data is present in a memory location in DS whose offset address is in BX. o The effective address, in this case, is computed as 10H*DS+[SI].

o The effective address of the data is given as 10H*DS+[BX]. o The content of address 10H*DS+[DI] will be transferred into register CX.

6. Register Relative 13
7. Based Indexed 14

 The effective address of data is formed, by adding content of a base register (any
 The data is available at an effective address formed by adding an 8-bit or
one of BX or BP) to the content of an index register (any one of SI or DI).
16-bit displacement with the content of any one of the registers BX, BP, SI
o The default segment register may be ES or DS.
and DI in the default (either DS or ES) segment.

 In first case, BX is the base register and SI is the index register.


o Here, the effective address is given as
o The effective address is computed as 10H*DS+[BX]+[SI]
10H*DS+50H+[BX] and
 In second case, BX is the base register and DI is the index register.
10H*DS+10H+[SI] respectively
o The effective address is computed as 10H*DS+[BX]+[DI]
8. Relative Based Indexed 15
Control Transfer Instructions 16

 The effective address is formed by adding an 8 or 16-bit displacement with the sum of
 The addressing modes depend upon whether the destination location is within the same
contents of any one of the base registers (BX or BP) and any one of the index registers, in a
segment or in a different one.
default segment.
 Also depends upon the method of passing the destination address to the processor.

 Two addressing modes for the control transfer instructions


o Inter-segment addressing modes: If the location to which the control is to be transferred lies in a
o 50H is an immediate displacement different segment other than the current one
o BX is a base register and SI is an index register. o Intra-segment addressing modes: If the destination location lies in the same segment
o The effective address of data is computed as 10H*DS+[BX]+[SI]+50H.

 The second instruction adds content of BP with memory location of which offset is given by
adding 50H of content of BX and SI. The result is stored in the memory location

9. Intra-segment Direct Mode 17


10. Intra-segment Indirect Mode 18

 The address to which the control is to be transferred lies in the same segment in which the
control transfer instruction lies and appears directly in the instruction as an immediate
 The displacement to which the control is to be transferred, is in the same
displacement value. segment in which the control transfer instruction lies, but it is passed to the
instruction indirectly.
 The displacement is computed relative to the content of the instruction pointer IP.

 The effective address to which the control will be transferred is given by the sum of current  The branch address is found as the content of a register or a memory location.
content of IP and 8 or 16 bit displacement.  This addressing mode may be used in unconditional branch instructions
o if the signed displacement (d) is of 8 bits (i.e. —128 < d < + 127), we term it as short jump and

o if the signed displacement is of 16 bits (i.e. —32768 < d < + 32767), it is termed as long jump.
o Assume current IP content is 5000H

o Jump to EA stored in BX
 LABEL lies within -128 to +127 from the current IP content .
i.e. JMP [ BX+5000H ]
o Thus SHORT LABEL is 8-bit signed displacement
11. Intersegment Direct 19
12. Intersegment Indirect 20

 The address to which the control is to be transferred is in a different  The address to which the control is to be transferred lies in a different segment and it
is passed to the instruction indirectly
segment.
o i.e. contents of a memory block containing 4 bytes -- IP(LSB), IP(MSB), CS(LSB) and CS(MSB)
 This addressing mode provides a means of branching from one code sequentially.

segment to another code segment.  The starting address of the memory block may be referred using any of the
addressing modes, except immediate mode.
o Here, the CS and IP of the destination address are specified directly in the
instruction.
o Jump to an address in the other segment specified at effective address 2000H in DS, that
points to the memory block as said above
o Jump to effective address 2000H in segment 5000H o IP(LSB), IP(MSB), CS(LSB) and CS(MSB) sequentially

Form effective addresses for different addressing modes 21


 Direct addressing mode: MOV AX, [5000H]  Based indexed: MOV AX, [BX] [SI]
22

 The contents of different registers

 Offset (displacement) = 5000H  [SP]-6000H


 [AX]-1000H  [CS]-0000H  Register indirect: MOV AX ,[BX]  Relative based indexed:
 [BX]-2000H  [DS]-1000H MOV AX, 5000 [BXJ [SI]

 [SI]-3000H  [SS]-2000H
 [DI]-4000H  [IP]-7000H
 [BP]-5000H  Register relative: MOV AX, 5000 [BX]

o Shifting a number four times to left is equivalent to multiplying it by 16D or 10H.


8086/8088 Instructions - Categories 25
8086/8088 Instructions 26

1. Data Copy/Transfer Instructions 5. Machine Control Instructions


o Used to transfer data from source operand to destination operand.
o These instructions control the machine status. NOP, HLT, WAIT and LOCK instructions
o All the store, move, load, exchange, input and output instructions belong to this category. belong to this class.
2. Arithmetic and Logical Instructions 6. Flag Manipulation Instructions
o Instructions performing arithmetic, logical, increment, decrement, compare and scan
o Instructions which directly affect the flag register
• The arithmetic instructions affect all the condition code flags.
o Instructions like CLC, STC, CLD,STD,CLI,STI, etc. belong to this category of instructions.
• The operands are either the registers or memory locations or immediate data depending on addressing mode

3. Branch Instructions 7. Shift and Rotate Instructions


o Transfer control of execution to the specified address. o Involve the bitwise shifting or rotation in either direction with or without a count in CX.
o All the call, jump, interrupt and return instructions belong to this class. 8. String Instructions
4. Loop Instructions o These instructions involve various string manipulation operations like load, move, scan,
o Used to implement unconditional and conditional loops. compare, store, etc.
o The loop instructions (LOOP, LOOPNZ, LOOPZ) belong to this category. o These instructions are only to be operated upon the strings

Data Copy/Transfer Instructions 29


MOV- Examples 30

1. MOV: (Move)  MOV AX, 5000H; Immediate


 Transfers data from one register/memory location / immediate data to another  MOV AX, [2000H]; Direct
register/memory location.
 MOV AX, BX; Register
o Source - any one of the segment registers or other general or special purpose registers or
a memory location or can be an immediate data ,  MOV AX, [BX]; Register Indirect
o Destination - another register or memory location.
 MOV AX, 50H[BX]; Based relative, 50H Displacement
• In case of immediate addressing mode, a segment register cannot be a destination register.

• To load the segment registers with immediate data, one will have to load any general purpose
 MOV DS, 5000H; Not permitted (invalid)
register with the data and then it will have to be moved to that particular segment register.
 MOV AX, 5000H
• Both the source and destination operands cannot be memory locations (except for string
instructions) MOV DS, AX Alternative (Valid)
Data Copy/Transfer Instructions 31
PUSH 32
2. PUSH: Push to Stack
 SS : SP points to the stack top and
 This instruction pushes the contents of the specified register/memory location on AH, AL contains data to be pushed.
to the stack.  The sequence of operation as below:
o Push operation decrements SP by 2 and then stores the two byte contents of the operand o Current stack top is already occupied
onto the stack so decrement SP by one then store
• The higher byte is pushed first (Higher Address )and then the lower byte ( Lower Address). AH into the address pointed to by SP.
o Further decrement SP by one and
Examples store AL into the location pointed to
by SP.
 PUSH AX • Thus SP is decremented by 2 and AH—
AL contents are stored in stack
 PUSH DS memory
• Contents of SP points to a new stack
 PUSH [5000H]; top.

• Content of location 5000H and 5001H in DS are pushed onto the stack

Data Copy/Transfer Instructions 33


POP 34

3. POP: Pop from Stack  16-bit contents of current stack top are poped into the specified operand as follows.
 Loads the specified register/memory location with the contents of the memory location of 1. Contents of stack top memory location is stored in AL and SP is incremented by one
which the address is formed using the current stack segment and stack pointer.
2. Further contents of memory location pointed to by SP are copied to AH and SP is again incremented by 1
 The stack pointer is incremented by 2.
3. Effectively SP is incremented by 2 and points to next stack top.
o The POP instruction serves exactly opposite to the PUSH instruction.

Examples

 POP AX

 POP DS

 POP [5000H];
Data Copy/Transfer Instructions 35
Data Copy/Transfer Instructions 36
4. XCHG: Exchange
5. IN: Input the Port
 Exchanges the contents of the specified source and destination operands
• May be registers or one of them may be a memory location.
 For reading an input port.
o Exchange of contents of two memory locations is not permitted.
o The address of the input port specified in the instruction directly or indirectly.

o Immediate data is also not allowed in these instructions.


o AL and AX are the allowed destinations for 8 and 16-bit input operations.
o DX is the only register (implicit) which is allowed to carry the port address (16 bit)

Examples Examples
 XCHG [5000H] , AX  IN AL , 03H --Reads data from an 8-bit port whose address is 03H and stores it in AL
• Exchanges data between AX and a memory location [5000H] in the data segment.  IN AX, DX --Reads data from a 16-bit port whose address is in DX and stores it in AX
 XCHG BX , AX o MOV DX,0800H --The 16-bit address is taken in DX

• Exchanges data between AX and BX. o IN AX, DX --Read the content of the port in AX

Data Copy/Transfer Instructions 37


Data Copy/Transfer Instructions 38
7. XLAT: Translate
6. OUT: Output to the Port
 Used for finding out the codes in case of code conversion problems, using look up table
 For writing to an output port.
technique.
o The address of the output port may be specified in the instruction directly or implicitly in DX (If the
o Suppose, a hexadecimal key pad having 16 keys from 0 to F is interfaced with 8086 and the number is
port address is of 16 bits )
displayed in 7 segment display device
o Contents of AX (16 bit) or AL (8 bit) are transferred to a directly or indirectly addressed port
o A look up table of codes is prepared to store the 7-segment codes for 0 to F at 16 locations (e.g. 2000H
o The data to an odd addressed port is transferred on D8-D15 while that to an even addressed port is to 200FH) sequentially
transferred on D0-D7.
 The following sequence of instructions perform the task.
Example
o MOV AX, SEG TABLE --Address of the segment containing look-up-table
 OUT 03H , AL ; This sends data available in AL to a port whose address is 03H. o MOV DS,AX --is transferred in DS
 OUT DX , AX ; This sends data available in AX to a port whose address is specified implicitly in DX. o MOV AL, CODE --Code of the pressed key is transferred in AL
o MOV DX , 0300H ; The 16-bit port address is taken in DX.
o MOV BX , OFFSET TABLE --Offset of the code look up table in BX
OUT DX , AX ; Write the content of AX to a port of which address is in DX.
o XLAT --Find the equivalent code and store in AL
Data Copy/Transfer Instructions 39
Data Copy/Transfer Instructions 40
7. LEA: Load Effective Address 9. LAHF : load AH from Lower Byte of Flag
 Loads the effective address formed by source register into the specified destination operand . o Loads the AH register with the lower byte of the flag register.
Examples
o Used to observe the status of all the condition code flags (except over flow) at a time.
o LEA BX, ADR : Offset of the Label-ADR will be transferred to Register BX.
10. SAHF: Store AH to Lower Byte of Flag Register
o LEA SI, ADR [BX]: offset of Label ADR will be added to content of BX to form effective address and it will be
loaded in SI o Sets or resets the condition code flags (except overflow) in the lower byte of the flag register depending upon
the corresponding bit positions in AH.
8. LDS/LES: Load Pointer to DS/ES

 Copies a word from memory locations into the register specified in the instruction.
11. PUSHF: Push Flags to Stack
 Then copies a word from the next memory locations into the DS(ES) register.
o Pushes the flag register on to the stack
 Useful for pointing to SI(DI) and DS(ES) in string operation.
• first the upper byte and then the lower byte is pushed on to it.
Example
o LDS BX, 5000H 12. POPF: Pop Flags from Stack
o LES BX, 5000H o The pop flags instruction loads the flag register (2 bytes) memory location addressed by SP and SS.

Arithmetic Instructions 43
Arithmetic Instructions 44
ADD: Add
Examples ADC: Add with Carry
 Adds an immediate data or contents of a memory
location specified in the instruction or a register (source) o ADD AX, 0100H Immediate  Same operation as ADD instruction, but adds the carry flag bit to the result
to the contents of another register (destination) or o ADD AX, BX Register • carry flag bit may be set as a result of the previous calculations
memory location. o ADD AX, [SI] Register indirect o All the condition code flags are affected by this instruction.
o Both the source and destination operands cannot be o ADD AX, [5000H] Direct
Example
memory operands. o ADD [5000H], 0100H Immediate
o ADC 0100H Immediate (AX implicit)
• Memory to memory addition is not possible. o ADD 0100H Destination AX
(implicit) o ADC AX, BX Register
o Contents of the segment registers cannot be added using
this instruction. o ADC AX, [SI] Register indirect

o All the condition code flags are affected, depending upon o ADC AX, [5000H] Direct
the result. o ADC [5000H], 0100H Immediate
Arithmetic Instructions 45
Arithmetic Instructions 46
SUB: Subtract
INC: Increment / DEC: Decrement
 Subtracts the source operand (a register, memory location or immediate data) from
 Increases/ Decreases the contents of the specified register or memory the destination operand (a register or a memory location) and the result is left in the
location by 1 [Data±1] destination operand.
o All the condition code flags are affected except the carry flag CF. o Source and destination operands both must not be memory operands.

o Immediate data cannot be operand of this instruction. o All the condition code flags are affected by this instruction

Examples Examples
o SUB AX, 0100H Immediate [destination AX]
o SUB AX, BX Register
o SUB AX, [5000H] Direct
o SUB [5000H], 0100 Immediate

Arithmetic Instructions 47
Arithmetic Instructions 48
SBB: Subtract with Borrow CMP: Compare

 Subtracts the source operand and the borrow flag (CF) which may reflect the result of the  Compares the source operand (a register or an immediate data or a memory location), with a destination
previous calculations, from the destination operand. operand (may be a register or a memory location)

o Subtraction with borrow, here means subtracting 1 from the subtraction obtained by SUB, if carry o For comparison, it subtracts the source operand from the destination operand but does not store the result anywhere.

(borrow) flag is set. o The flags are affected depending upon the result of the subtraction.
• If both of the operands are equal, zero flag is set.
o The result is stored in the destination operand.
• If the source operand is greater than the destination operand, carry flag is set
o All the flags are affected (Condition code) by this instruction.
• If the source operand is less than the destination operand , carry flag is reset.
Examples  The examples of this instruction are as follows:
o SBB AX, 0100H Immediate [destination AX] o CMP AX, 0100H Immediate
o SBB AX, BX Register o CMP [5000H], 0100H Direct
o SBB AX, [5000H] Direct o CMP BX, [SI] Register indirect
o SBB [5000H], 0100 Immediate o CMP BX, CX Register
Arithmetic Instructions 49
Arithmetic Instructions 50

MUL: Unsigned Multiplication Byte or Word IMUL: Signed Multiplication

 Multiplies an unsigned byte or word (from a general purpose registers or memory  Multiplies a signed byte or word in source operand by a signed byte in AL or AX.
locations) by the contents of AL or AX. o In case of 32-bit results, the higher order word (MSW) is stored in DX and the lower order word
o The most significant word of the result is stored in DX (LSW) is stored in AX.

o The least significant word of the result is stored in AX. o The AF, PF, SF, and ZF flags are undefined after IMUL.

o All the flags are modified depending upon the result. o If AH and DX contain parts of 16 and 32-bit result respectively,
• CF and OF both will be set.
o Immediate operand is not allowed in this instruction.
o The AL and AX are the implicit operands in case of 8 bits and 16 bits multiplications respectively.
o If the most significant byte or word of the result is ‘0’
• CF and OF both will be set.
o The unused higher bits of the result are filled by sign bit and CF, AF are cleared.

Arithmetic Instructions 51
Arithmetic Instructions 52
DIV: Unsigned Division NEG: Negate
 It divides an unsigned word or double word by a 16-bit or 8-bit operand.  The negate instruction forms 2’s complement of the specified destination in
 The dividend must be in AX for 16-bit operation and divisor may be specified using any one of the the instruction.
addressing modes except immediate.
 For obtaining 2’s complement, it subtracts the contents of destination from zero.
o The result will be in AL (quotient) while AH will contain the remainder.

o If the result is too big to fit in AL, type 0 (divide by zero) interrupt is generated.  The result is stored back in the destination operand which may be a register or a
 In case of a double word dividend (32-bit)- The higher word in DX and lower word in AX. memory location.
o The quotient and the remainder, in this case, will be in AX and DX respectively.  If OF is set, it indicates that the operation could not be completed successfully.
 This instruction does not affect any flag.
 This instruction affects all the condition code flags.
IDIV: Signed Division

 Same operation as the DIV instruction, but with signed operands and signed Results
Arithmetic Instructions 53
Arithmetic Instructions 54

CBW: Convert Signed Byte to Word DAA: Decimal Adjust Accumulator

 Used to convert the result of the addition of


 Copies the sign bit of a byte to be converted to all the bits in the higher byte
two packed BCD numbers to a valid BCD number.
of the result word.
o The result has to be only in AL.
 The byte to be converted must be in AL. The result will be in AX.  If the lower nibble is greater than 9, or if AF is
 It does not affect any flag. set
o Will add 06 to the lower nibble in AL.
CWD: Convert Signed Word to Double Word
o After adding 06 in the lower nibble, if the upper
 This instruction copies the sign bit of AX to all the bits of the DX register. nibble of AL is greater than 9 or if CF=1

DAA instruction adds 60H to AL.


 This operation is to be done before signed division.
 The instruction DAA affects AF, CF, PF, and ZF flags.
 It does not affect any flag.

Arithmetic Instructions 55
Arithmetic Instructions 56
DAS: Decimal Adjust after Subtraction AAA: ASCII Adjust After Addition

 Performed after an addition of two ASCII coded operands to give a byte of result in AL.
 This instruction converts the result of subtraction of two packed BCD numbers to a valid BCD
o Converts the resulting contents of AL to unpacked decimal digits.
number.
 When lower 4 bits of AL is checked for a valid BCD number in the range 0 to 9
o The subtraction has to be in AL only.  If it is between 0 to 9 and AF is zero

 If the lower nibble of AL is greater than 9 o AAA sets the 4 high order bits of AL to 0 [The AH must be cleared before addition]

 If the lower digit of AL is between 0 to 9 and AF is set


o Will subtract 06 from lower nibble of AL.
o 06 is added to AL, The upper 4 bits of AL are cleared and AH is incremented by 1.
 If the result of subtraction sets the carry flag or if upper nibble is greater than 9,  If the value in the lower nibble of AL is greater than 9 then

o Will subtracts 60H from AL. o AL is incremented by 06, AH is incremented by 1

o AF and CF flags are set to 1, The remaining flags are unaffected


 Modifies the AF, CF, SF, PF &ZF flags.
o Higher 4 bits of AL are cleared to 0.

o The OF is undefined after DAS. o The AH is modified as sum of previous contents (usually 00) and the carry from the adjustment

 This instruction does not give exact ASCII codes of the sum, but they can be obtained by adding 3030H to AX.
Arithmetic Instructions 57
Arithmetic Instructions 58
AAM : ASCII Adjust after Multiplication
AAS: ASCII Adjust AL after Subtraction
 After execution, converts the product available in AL into unpacked BCD format.
 AAS instruction corrects the result in AL register after subtracting two unpacked ASCII operands.
 Follows a multiplication instruction that multiplies two unpacked BCD operands
o The result is in unpacked decimal format.
o higher nibbles of the multiplication operands should be 0.
 If the lower 4 bits of AL register are greater than 9 or if the AF flag is 1 o The multiplication of such operands is carried out using MUL instruction.
o AL is decremented by 6 and AH register is decremented by 1 o Result of multiplication is available in AX.
o CF and AF are set to 1.

 Otherwise, AAD: ASCII Adjust before Division


o CF and AF are set to 0,
 Converts two unpacked BCD digits in AH and AL to the equivalent binary number in AL.
o Result needs no correction.
o This adjustment must be made before dividing the two unpacked BCD digits in AX by an unpacked BCD byte.
o As a result, the upper nibble of AL is 00 and the lower nibble may be any number from 0 to 9.
o PF, SF, ZF are modified while AF, CF, OF are undefined, after the execution of the instruction AAD.
 The procedure is similar to the AAA instruction except for the subtraction of 06 from AL.
o AH is modified as difference of the previous contents (usually zero) of AH and the borrow for adjustment.

Logical Instructions 61
Logical Instructions 62
AND: logical AND
 These type of instructions are used for carrying out the bit by bit  This instruction bit by bit ANDs the source operand to the destination operand
o Source may be an immediate, a register or a memory location
shift, rotate, or basic logical operations.
o Destination may be a register or a memory location.

 All the condition code flags are affected depending upon the • At least one of the operands should be a register or a memory operand.

• Both the operands cannot be memory locations or immediate operands.


result. • An immediate operand can- not be a destination operand.

 Basic logical operations available with 8086 instruction set are

AND, OR, NOT, and XOR.


Logical Instructions 63
Logical Instructions 64

OR: logical OR NOT: logical Invert


 The OR instruction carries out the OR operation in the same way as  The NOT instruction complements (inverts) the contents of an operand
described in case of the AND operation. register or a memory location, bit by bit.

Logical Instructions 65
Logical Instructions 66

XOR: Logical Exclusive OR TEST: Logical Compare Instruction


 The XOR operation is again carried out in a similar way to the AND and OR operation.  The TEST instruction performs a bit by bit logical AND operation on the two
o The XOR operation gives a high output, when the 2 input bits are dissimilar. operands.
o Otherwise, the output is zero. o if the corresponding bits of both operands are 1, Each bit of the result is then set to 1, else
the result bit is reset to 0.

o The result of this AND ing operation is not available for further use
• But flags (OF, CF, SF, ZF and PF) are affected.

o The operands may be registers, memory or immediate data.


String Manipulation Instructions 69
String Manipulation Instructions 70
Byte strings or Word strings: A series of data bytes or words available in memory at consecutive
locations. REP: Repeat Instruction Prefix
• For example, a string of characters may be located in consecutive memory locations, where each character may be
represented by its ASCII equivalent.  This instruction is used as a prefix to other instructions.
 For referring to a string, two parameters are required, o The instruction to which the REP prefix is provided, is executed
a) starting or end address of the string and
repeatedly until the CX register becomes zero
b) length of the string. [The length of a string is usually stored as count in the CX register].
• At each iteration CX is automatically decremented by 1
 The incrementing or decrementing of the pointer, depends upon the Direction Flag (DF) status.
• When CX becomes zero, the execution proceeds to the next instruction in sequence.
o If it is a byte string operation, the index registers are updated by one.

o If it is a word string operation, the index registers are updated by two. o There are two more options of the REP instruction.
o The counter in both the cases, is decremented by one. • The first is REPE/ REPZ, i.e. repeat operation while equal/zero.

• The second is REPNE/REPNZ for repeating the operation while not equal/not zero.

String Manipulation Instructions 71


String Manipulation Instructions 72

MOVSB/MOVSW: Move String Byte or String Word


CMPS: Compare String Byte or String Word
 A string of bytes stored in consecutive locations is moved to another set of destination locations.
o a string of bytes/words pointed by DS: SI pair (source) to destination pointed to by ES: DI pair.
 Compare two strings of bytes or words- Byte by Byte / Word by
o No flags are affected by this instruction. Word
 The incrementing or decrementing of the pointers (SI and DI ) depend upon the direction flag DF. o The length of the string in CX.
o If DF is 0, the index registers are incremented, otherwise, they are decremented
o The flags (ZF and CF) are affected in the same way as CMP instruction

o The DS: SI and ES: DI point to the two strings.

o After each comparison the index registers are updated depending upon DF
and the counter is decremented
String Manipulation Instructions 73
String Manipulation Instructions 74

SCAS: Scan String Byte or String Word


 Search for a byte/word specified by AL/AX in a string of bytes or words
o The string is pointed to by ES: DI register pair.

o The length of the string is stored in CX and The DF controls the mode for scanning

o When a match is found in the string, execution stops and the zero flag is set.
• If no match is found, the zero flag is reset.

String Manipulation Instructions 75


Control Transfer or Branching Instructions 78

LODS: load String Byte or String Word


 Transfer the flow of execution of the program to a new address specified in
 Loads the AL/AX register by the content of a string pointed to by DS: SI register pair.
the instruction directly or indirectly.
o The SI is modified automatically depending upon DF.
o CS and IP registers get loaded with new values.
o If it is a byte transfer(LODSB), the SI is modified by 1 and if it is word transfer(LODSW), the SI
modified by 2.  This type of instructions are classified in two types:
o Unconditional Control Transfer (Branch) Instructions
STOS: Store String Byte or String Word
• Execution control is transferred to the specified location independent of any status or
 Stores the AL/AX register contents to a location in the string pointed by ES: DI register pair. condition.

o DI modified after each iteration automatically. o Conditional Control Transfer (Branch) Instructions
o DF controls the direction of operation • Control is transferred to the specified location if a particular flag satisfies the condition in the
previous result.
Unconditional Branch Instructions 81
Unconditional Branch Instructions 82

CALL: Unconditional Call


RET: Return from the Procedure
 Used to call a subroutine from a main program.
 At the end of the procedure (Subroutine), the RET instruction must be executed.
o The address of subroutine be specified directly or indirectly depending on the addressing mode.
o Previously stored IP and CS along with flags are retrieved from the stack
 There are again two types of procedures
o Execution of the main program continues further.
o Near CALL, i.e. +32K displacement in Same SEGMENT Intrasegment
 Depending on the type of procedure and the SP contents, the RET instruction is of four types.
o FAR CALL, i.e. anywhere outside the segment (Different Segment) Intersegment
o Return within segment
 Stores the incremented IP (i.e. address of the next instruction) and CS onto the stack
o Return within segment adding 16-bit immediate displacement to the SP contents.
 Loads the CS and IP registers with the segment and offset addresses of the procedure to be o Return intersegment
called.
o Return intersegment adding 16-bit immediate displacement to the SP contents.
o In case of NEAR CALL it pushes only IP register

o In case of FAR CALL it pushes IP and CS both onto the stack.

Unconditional Branch Instructions 83


Unconditional Branch Instructions 84

INT N: Interrupt Type N


 For interrupt Vector Table
 In 8086/8088, 256 interrupts are defined from type 00H to type FFH.
o When an INT N instruction is executed
• TYPE byte N is multiplied by 4

• IP of interrupt service routine (ISR) N*4 offset address

• Segment address, CS of ISR 0000 .

o For the execution of this instruction, the IF must be enabled


Unconditional Branch Instructions 85
Unconditional Branch Instructions 86

INTO: Interrupt on Overflow JMP: Unconditional Jump

 Unconditionally transfers the control of execution to


 Executed, when the overflow flag OF is set.
o A specified address using an 8-bit or 16-bit displacement (intra-segment relative, short or long) or
o This is equivalent to a Type 4 interrupt instruction
o CS: IP (inter-segment direct far).
o The new contents of IP and CS are taken from the address 0000:0010 [4*4=16=10H]
o No flags are affected by this instruction.

IRET: Return from ISR


 At the end of each ISR
o When IRET is executed, the values of IP, CS and flags of previous execution are
retrieved from the stack

Unconditional Branch Instructions 87


Conditional Branch Instructions 88

LOOP: Loop Unconditionally


 When these instructions are executed
 Executes the part of the program from the label or address specified in the instruction up to
the loop instruction, CX number of times. o Execution control is transferred to the address specified relatively in
 Sequence of execution.
the instruction
o At each iteration, CX is decremented automatically.
• Condition (Status of Flags) implicit in the opcode is satisfied.
• DECREMENT COUNTER and JUMP IF NOT ZERO structure.

o No flags are affected by this instruction • If not, the execution continues sequentially.

o Do not affect any flag.

o Only short jumps can be implemented using conditional branch


instructions.
Signed Operation
89
Conditional Loop 90

Flag Manipulation & Process Control Instructions 93


Flag Manipulation Instructions 94

 Control the functioning of the available hardware inside the


processor chip.

 These are categorized into two type

(a) Flag manipulation instructions  The DF and IF controls the processor operation by interrupt responses and
• directly modify some of the flags of 8086 auto-increment or auto-decrement modes.
o Also be called machine or processor control instructions.
(b) Machine control instructions
 The other flags can be modified using POPF and SAHF instructions,
• control the bus usage and execution.
o Data transfer instructions
Flag Manipulation & Process Control Instructions 95
Assembler Directives and Operators 98

 Advantages of assembly language programs (ALP) compared to

Machine Language
 HLT  Processor enters the halt state.
o The instruction mnemonics are directly written in ALP.
o To pull out of the halt state are to reset the processor or to interrupt it.

 NOP  Processor does not perform any operation till 4 clock cycles o The address values and constants can be identified by labels 
 ESC frees the bus for an external master (coprocessor or peripheral devices.) More understandable Easy to handle and manipulate data
 LOCK prefix may appear with another instruction
o Documentation facility (which was not possible with machine language
o Used in case of programming for multiprocessor systems.

o Bus access is not allowed for another master till the other instruction is executed programming)
 WAIT  Holds the operation of processor with the current status till TEST# pin goes low.

Assembler 99
Assembler Directive 10
0

 An assembler is a program used to convert an assembly language program (ALP) into the  For completing all the tasks, an assembler needs to know
equivalent machine code modules which may further be converted to executable codes.
o Required storage for a particular constant or a variable
ALP ML Hex Code
Assembler
(Assembly Language Program) (Machine Language) (Executable Program)
o Logical names of the segments

 Operations of ASSEMBLER o Types of the different routines and modules


o It decides the address of each label and substitutes the values for each of the constants and variables. o End of file
o It then forms the machine code for the mnemonics and data in the ALP.
 Assembler Directives are some predefined alphabetical strings that
• While doing these things, the assembler may find out syntax errors.

• The logical errors or other programming errors are not found out by the assembler.
give these types of hints to the assembler
• They help the assembler to understand the programs to prepare the codes.
Operator 10
1
Assembler Directives and Operators 10
2
DB: Define Byte
 Operator is another type of hint that helps assembler
 To reserve byte or bytes of memory locations in the available memory, While preparing the EXE file.

o To assign a particular constant with a label or o Directs the assembler to allocate the specified no. of memory bytes to the said data type (constant, variable,
string, etc. ),
o Initialise particular memory locations or Examples
o labels with constants . RANKS DB 01H, 02H, 03H, 04H
o Directs the assembler to reserve 4 memory locations for a list named RANKS
o Initialise them with the above specified 4 values
 Operators perform the arithmetic and logical tasks unlike
MESSAGE DB ’GOOD MORNING'
Assembler Directives (that just direct the assembler to correctly o Reserve the no. of bytes of memory equal to the number of characters in the string named MESSAGE
o Initialise those locations by the ASCII equivalent of these characters.
interpret the program to code it appropriately).
VALUE DB 50H
o Reserve 50H memory bytes and leave them uninitialized for the variable named VALUE.

Assembler Directives and Operators 10


3
Assembler Directives and Operators 10
4

DW: Define Word


DQ: Define Quad-word
 Same purposes as the DB directive, but to reserve the number of memory words (16-bit) instead of
bytes
 Reserve 4 words (8 bytes) of memory for the specified variable and
Examples
may initialise it with the specified values.
WORDS DW 1234H , 4567H , 78ABH , 045CH ,
o Reserve 4 words in memory (8 bytes) DT: Define Ten Bytes
o initialize the words with the specified values in the statement
 Define the specified variable requiring 10-bytes for its storage and
• Lower bytes are stored at the lower memory addresses & upper bytes are stored at the higher addresses.
initialise the 10-bytes with the specified values.
WDATA DW 5 DUP (6666H)
o Reserves 5 words, i.e. 10-bytes of memory for a word label WDATA o The directive may be used in case of variables facing heavy numerical
o initialises all the word locations with 6666H. calculations, generally processed by numerical processors.
Assembler Directives and Operators 10
5
Assembler Directives and Operators 10
6
ASSUME: Assume logical Segment Name END: END of Program

 Used to inform the assemble, the names of the logical segments to be assumed for  Marks the end of an assembly language program.
different segments used in the program. o When the assembler comes across this END directive, it ignores the source lines available later on.
o Each segment is given a name. CODE for code segment, DATA for data segment etc.
o END statement should be the last statement in the file and should not appear in between.
o The ASSUME statement is a must at the starting of each assembly language program
without which a message ‘CODE/DATA EMITTED WITHOUT SEG MENT’ may be issued by an assembler. ENDP: END of Procedure
Example  The ENDP directive is used to indicate the end of a procedure (subroutine).
 ASSUME CS : CODE o The Procedure name (label) may appear as a prefix with the directive ENDP.
o Directs the assembler that the machine codes are available in a segment named CODE
ENDS: END of Segment
o Segment CODE consider as a source segment for the machine codes of the program
 ASSUME DS : DATA  Marks the end of a logical segment.
o indicates to the assembler that the data items related to the program, are available in a logical segment o The names appear with the ENDS directive as prefixes.
named DATA
o Segment DATA consider as a default data segment for each memory operation, related to the data o Any statement after ENDS will be neglected from the segment.

Assembler Directives and Operators 10


7
Assembler Directives and Operators 10
8

EVEN: Align on Even Memory Address EQU: Equate


 The EVEN directive updates the location counter to the next even address  Used to assign a label with a value or a symbol to reduce the recurrence of the
o a location counter initialises and goes on updating as the assembly proceeds. numerical values or constants in a program code.
o It goes on assigning the available addresses (contents of the location counter), sequentially to the program o The recurring value is assigned with a label, and that label is used in place of that
variables (constants and modules) numerical value, throughout the program.
o Figure shows a procedure ROOT that is to be aligned at an even address. o While assembling, whenever the assembler comes across the label, it substitutes the
o The assembler will start assembling the main program which calls ROOT. numerical value for that label and finds out the equivalent code.
o When the assembler comes across the directive EVEN, it checks the contents of the location counter. o If the EQU directive is used to assign the value with a label that can be used in place of
• If it is odd, it is updated to the next even value and then the ROOT procedure is assigned to that address each recurrence of that constant, only one change in the EQU statement will give the
• If the content of the location counter is already even, then the ROOT procedure will be assigned with the same address. correct and modified code.
Assembler Directives and Operators 10
9
Assembler Directives and Operators 11
0

EXTRN: External and PUBLIC: Public GROUP: Group the Related Segments

 EXTRN informs the assembler that the names, procedures and labels declared after this  Used to form logical groups of segments with similar purpose or type.
directive have already been defined in some other assembly language modules.  Used to inform the assembler to form a logical group of the following segment names.

o While in the other module, where the names, procedures and labels actually appear, they must be  The assembler passes an information to the linker/loader to form the code such that the group
declared public, using the PUBLIC directive. declared segments or operands must lie within a 64Kbyte memory segment.

 The statement of declaration EXTRN must be accompanied by the SEGMENT and ENDS o Thus all such segments and labels can be addressed using the same segment base.

directives of the MODULE 1, before it is called in MOBULE 2. PROGRAM GROUP CODE, DATA, STACK

o Thus the MODULE 1 and MODULE 2 must have the following declarations. o The above statement directs the loader/linker to prepare an EXE file such that CODE, DATA and STACK
segment must lie within a 64kbyte memory segment that is named as PROGRAM.

o Now, for the ASSUME statement, one can use the label PROGRAM rather than CODE, DATA and STACK as
shown.

ASSUME CS: PROGRAM, DS: PROGRAM, SS: PROGRAM

Assembler Directives and Operators 11


1
Assembler Directives and Operators 11
2
LABEL: Label
LENGTH: Byte length of a Label
 Used to assign a name to the current content of the location counter.
 Used to refer to the length of a data array or a string.
o The type of the label must be specified, i.e. whether it is a NEAR or a FAR label, BYTE or WORD label, etc.
MOV CX, LENGTH ARRAY
o The label CONTINUE can be used for a FAR jump, if the program contains the following statement.
o When assembled, the length of the array ARRAY will be substituted in bytes
CONTINUE LABEL FAR
LOCAL:
o The LABEL directive can be used to refer to the data segment along with the data type, byte or word as
shown.  The labels, variables, constants or procedures declared LOCAL in a module are to be used only by that
particular module.
o After some time, some other module may declare a particular data type LOCAL by an other module or modules.

o With a single declaration statement, a number of variables can be declared local, as shown.

o After reserving 50H locations for DATAS, the next location will be assigned a label DATA-LAST and its type will LOCAL a, b, DATA, ARRAY, ROUTINE
be byte and far.
Assembler Directives and Operators 11
3
Assembler Directives and Operators 11
4

ORG : Origin
NAME: logical Name of a Module
 Directs the assembler to start the memory allotment for the particular segment, block or
 The NAME directive is used to assign a name to an assembly language program module.
code from the declared address in the ORG statement.
o The names may point out the functions of the different modules and hence may help in the documentation.
o ORG 200H will start the code from 0200H instead of 0000H (default) in code segment
OFFSET: Offset of a label
• Code for different modules and segments can be located in the available memory.
 Used to decide the offsets of arrays, strings, labels and procedures in their default segments
PROC: Procedure
o OFFSET operator with a label, computes the 16-bit displacement (offset) of the particular label, and replaces
the string ‘OFFSET LABEL’ by the computed displacement.  Marks the start of a named procedure, as well as its type (NEAR or FAR) in the statement.
o Commonly used in indirect, indexed, based indexed addressing types to refer to the memory indirectly. o RESULT PROC NEAR marks start of a routine RESULT located in the same segment of memory.
• FAR directive is used for the procedures to be called in different segments of memory.

Assembler Directives and Operators 11


5
Assembler Directives and Operators 11
6
PTR: Pointer
SEG: Segment of a label
 Used to declare the type of a label, variable or memory operand.
 Used to decide the segment address of the label, variable, or procedure and substitutes the
o PTR is prefixed by either BYTE or WORD to specify the data type
segment base address in place of “SEG” label.
o In case of JMP instructions, the PTR operator is used to specify the type of the jump, i.e. near or far

JMP NEAR PTR [BX]-NEAR Jump

JMP FAR PTR [BX]-FAR Jump. SEGMENT: logical Segment

 Marks the starting of a logical segment.


o Two type
• PUBLIC (i.e. can be used by other modules of the program while linking) or

• GLOBAL (can be accessed by any other modules).


Assembler Directives and Operators 11
7
Assembler Directives and Operators 11
8
PUBLIC GLOBAL
 PUBLIC directive is used along with the EXTRN directive.  The labels, variables, constants or procedures declared GLOBAL may be used by other modules of the
program.
o PUBLIC declared labels, variables, constants or procedures, must be declared externally using the
EXTRN directive. ROUTINE PROC GLOBAL – Declares the procedure ROUTINE globally

SHORT: FAR PTR

 Indicates that only one byte is required to code the displacement for a jump.  Indicates the assembler that the label following FAR PTR is not available within the same segment
o 2 bytes offset followed by 2 bytes segment address to address it-32 bit address
o Otherwise, the assembler may reserve two bytes for the displacement.
JMP SHORT LABEL

TYPE NEAR PTR

 Directs the assembler to decide the data type of the specified label and replaces the ‘TYPE’  Indicates that the label following NEAR PTR is in the same segment
label by data type. o 2 byte offset to address it- 16 bit address.

o For word type variable, the data type is 2, for double word type, it is 4, and for byte type, it is 1.  If a label is not preceded by NEAR PTR or FAR PTR, then it is by default considered a NEAR PTR label
MOV AX, TYPE STRING moves the value 0002H in AX, if STRING is a word array

1. Write a program to add a data byte located at offset 0500H in 2000H


Assembler Directives and Operators 11
9
segment to another data byte available at 0600H in the same segment and
12
2

store the result at 0700H in the same segment.


‘+ & —’ Operators
 Represent arithmetic addition and subtraction MOV AX, 2000H ; Initialising DS with value
o Used to add or subtract displacements to base/index registers or stack/base pointers MOV DS, AX ; 2000H
MOV AX, [500H] ; Get first data byte from 0500H offset
ADD AX, [600H] ; Add this to the second byte from 0600H
MOV [700H], AX ; Store AX in 0700H (result).
HLT ; Stop
2. Write a program to move the contents of the memory location 0500H to register BX 12 3. Add the contents of the memory location 2000H:0500H to contents of 12
and to CX. Add immediate byte 05H to the data residing in memory location, whose 3 4
3000H:0600H and store the result in 5000H:0700H.
address is computed using DS = 2000H and offset = 0600H. Store the result of the
addition in 0700H.
[Assume that the data is located in the same segment]

4. Move a byte string, 16-bytes long, from the offset 0200H to 12 4. Move a byte string, 16-bytes long, from the offset 0200H to 12
5 6
0300H in the segment 7000H. 0300H in the segment 7000H.
 --Alternative Method using LOOP instruction--
4. Move a byte string, 16-bytes long, from the offset 0200H to 12 5. Find out the largest number from an unordered array of sixteen 8-bit 12
7 8
0300H in the segment 7000H. numbers stored sequentially in the memory locations starting at offset
0500H in the segment 2000H.
 --Alternative Method using String instructions--

12
9
Disadvantages of machine level programming 13
0

 The process is complicated and time consuming.

 The chances of error being committed are more at the machine

level in hand-coding and entering the program byte-by-byte into

Assembler the system.


 Debugging a program at the machine level is more difficult.

 The programs are not understood by everyone and the results are

not stored in a user-friendly form.


Assembly level programming 13
1
Advantages of Assembly level programming 13
2

 The programming in assembly language is not so complicated as in machine language because the
 A program called ‘assembler’ is used to convert the mnemonics of
function of coding is performed by an assembler.
instructions along with the data into their equivalent object code  The chances of error being committed are less because the mnemonics are used instead of numerical
modules. opcodes. It is easier to enter an assembly language program.

 As the mnemonics are purpose-suggestive the debugging is easier.


 These object code modules may further be converted in executable
 The constants and address locations can be labeled with suggestive labels hence imparting a more friendly
code using the linker and loader programs. interface to user.

 In assembly language programming, the mnemonics are directly used  Advanced assemblers provide facilities like macros, lists, etc. making the task of programming much easier.

 The results may be stored in a more user-friendly form.


in the user programs.
 The flexibility of programming is more in assembly language programming as compared to machine
 The assembler performs the task of coding. language because of advanced facilities available with the modern assemblers.

Assemblers 13
3
13
4

 Assembler is a program that converts an assembly input file (source file) to an object
file that can further be converted into machine codes (executable file) using a linker.
 The recent versions of the assembler are designed with many facilities like macro-
assemblers, numerical processor assemblers, procedures, functions and so on. Programming with an
 There are a number of assemblers available like MASM, TASM and DOS assembler.
Assembler
 MASM (Microsoft Macro Assembler) is one of the popular assemblers used along
with a LINK program (to structure the codes generated by MASM in the form of an executable file).
 MASM reads the source program as its input and provides an object file.
 The LINK accepts the object file produced by MASM as input and produces an EXE file
1. Write a program for addition of two numbers 13
5
1. Write a program for addition of two numbers 13
6

 --Alternative Method--

2. Write a program for the addition of a series of 8-bit 13 2. Write a program for the addition of a series of 8-bit numbers. The series 13
7 8
contains 100(numbers).
numbers. The series contains 100(numbers).
3. A program to find out the largest number from a given unordered array 13 3. A program to find out the largest number from a given unordered array 14
9 0
of 8-bit numbers, stored in the locations starting from a known address. of 8-bit numbers, stored in the locations starting from a known address.

4. A program to find out the largest number from a given unordered array 14 5. A program to find out the number of even and odd numbers from a 14
1 2
of words, stored in the locations starting from a known address. given series of 16-bit hexadecimal numbers.
6. Write a program to find out the number of positive numbers and 14 7. Write a program to move a string of data words from offset 2000H to 14
3 4
negative numbers from a given series of signed numbers. offset 3000H the length of the string is 0FH.

7. Write a program to move a string of data words from offset 2000H to 14 8. Write an assembly language program to arrange a given series of 14
5 6
offset 3000H the length of the string is 0FH. hexadecimal bytes in ascending order.

 --Alternative method--  Out of different sorting algorithms, bubble sorting logic is used

here.
8. Write an assembly language program to arrange a given series of 14 8. Write an assembly language program to arrange a given series 14
7 8
hexadecimal bytes in ascending order. of hexadecimal bytes in ascending order.
 Procedure of bubble sorting logic.
 First number of the series is compared with the second one.
 If the first number is greater than second, exchange their positions in the series otherwise leave the positions unchanged.

 Then, compare the second number in the recent form of the series with third
 Repeat the exchange part that you have carried out for the first and the second number, and for all the remaining numbers
of the series.

 Repeat this procedure for the complete series (n —1) times.


 After (n —1) iterations, you will get the largest number at the end of the series, where n is the length of the
series.
 Again start from the first address of the series. Repeat the same procedure right from the first element to
the last element.
 After (n —2) iterations you will get the second highest number at the last but one place in the series.
 Continue this till the complete series is arranged in ascending order.

9. Write a program to perform a one byte BCD addition 14 9. Write a program to perform a one byte BCD addition 15
9 0
10. Write a program that performs addition, subtraction, multiplication and division of 15 11. Write a program to find out whether a given byte is in the string or not. 15
the given operands. Perform BCD operation for addition and subtraction 1 2
If it is in the string, find out the number of times the given byte repeated
in the string.

12. Decide whether the parity of a given number is even or odd. If parity is 15 13. Write a program for the addition of two 3 x 3 matrices. The matrices 15
3 4
even set DL to 00; else, set DL to 01. The given number may be a multibyte are stored in the form of lists (row wise). Store the result of addition in the
number third list.
13. Write a program for the addition of two 3 x 3 matrices. The matrices are stored in 15 14. Write a program to find out the product of two matrices. 15
the form of lists (row wise). Store the result of addition in the third list. 5 6
Store the result in the third matrix. The matrices are specified as
in the previous Program

14. Write a program to find out the product of two matrices. Store the 15 14. Write a program to find out the product of two matrices. Store the result in the 15
7 third matrix. The matrices are specified as in the previous Program 8
result in the third matrix. The matrices are specified as in the previous
Program
15. Write a program to convert a 16 bit binary number into equivalent BCD 15 16. Write a program to convert a BCD number into an equivalent binary 16
9 0
number number.

17. Write a program to convert an 8 bit binary number into equivalent gray 16 17. Write a program to convert an 8 bit binary number into equivalent gray 16
1 2
code. code.
18. Find square root of a two digit number. Assume that the number is a 16 16
3 4
perfect square.

Programming with Subroutine

1. Write a program to calculate squares of BCD numbers 0 to 9 and store them 16 16


sequentially from 2000H offset onwards in the current data segment. The numbers and 5 6
their squares are in the BCD format. Write a subroutine for the calculation of the
square of a number.
2. Write a program to change a sequence of sixteen 2-byte numbers from ascending to 16 2. Write a program to change a sequence of sixteen 2-byte numbers from 16
descending order. The numbers are stored in the data segment. Store the new series at 7 8
ascending to descending order. The numbers are stored in the data
addresses starting from 6000 H. Use the LIFO property of the stack
segment. Store the new series at addresses starting from 6000 H. Use the
LIFO property of the stack

Passing Parameter to Procedures- Parameter Declared Global 16 Passing Parameter to Procedures- Storing Parameters in GPR 17
9 0
Passing Parameter to Procedures- Storing Parameters in Memory 17 Passing Parameter to Procedures- Using Stack 17
1 2

Passing Parameter to Procedures- Using PUBLIC & EXTERN 17


3

You might also like