33
Chapter 3 Q. Describe various addressing mode used in 8086 instructions with example. (Any 4 addressing modes : ½ Mark explanation, ½ Mark one example of each) Ans: Different addressing modes of 8086 : 1. Immediate : In this addressing mode, immediate data is a part of instruction, and appears in the form ofsuccessive byte or word. E.g.: MOV AX, 005OH 2. Direct :`In the direct addressing mode, a 16 bit address (offset) is directly specified in the instruction as a part of it. E.g.:.MOV AX ,[1 0 0 0 H] 3. Register :In register addressing mode, the data is stored in a register and it is referred using the particular register. All the registers except IP may be used in this mode. E.g.:. 1)MOV AX,BX 2)ROR AL,CL 3) AND AL,BL 4. Register Indirect: In this addressing mode, the address of the memory location which contains data or operand is determined in an indirect way using offset registers. The offset address of data is in either BX or SI or DI register. The default segment register is either DS or ES. e.g. MOV AX, BX 5. Indexed :In this addressing mode offset of the operand is stored in one of the index register. DS and ES are the default segments for index registers SI and DI respectively e.g. MOV AX, SI 6. Register Relative :In this addressing mode, the data is available at an effective address formed by adding an 8-bit or 16-bit displacement with the content of any one of the registers BX, BP, SI and DI in the default either DS or ES segment. e.g. MOV AX, 50HBX 7. Based Indexed: In this addressing mode, the effective address of the data is formed by adding the content of a base register (any one of BX or BP) to the content of an index register (any one of SI or DI). The default segment register may be ES or DS. Page No.1

thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

Q. Describe various addressing mode used in 8086 instructions with example.(Any 4 addressing modes : ½ Mark explanation, ½ Mark one example of each)Ans: Different addressing modes of 8086 :1. Immediate : In this addressing mode, immediate data is a part of instruction, and appears in the form ofsuccessive byte or word. E.g.: MOV AX, 005OH2. Direct :`In the direct addressing mode, a 16 bit address (offset) is directly specified in the instruction as a part of it. E.g.:.MOV AX ,[1 0 0 0 H]3. Register :In register addressing mode, the data is stored in a register and it is referred using the particular register. All the registers except IP may be used in this mode.E.g.:. 1)MOV AX,BX 2)ROR AL,CL 3) AND AL,BL4. Register Indirect: In this addressing mode, the address of the memory location which contains data or operand is determined in an indirect way using offset registers. The offset address of data is in either BX or SI or DI register. The default segment register is either DS or ES. e.g. MOV AX, BX 5. Indexed :In this addressing mode offset of the operand is stored in one of the index register. DS and ES are the default segments for index registers SI and DI respectivelye.g. MOV AX, SI 6. Register Relative :In this addressing mode, the data is available at an effective address formed by adding an 8-bit or 16-bit displacement with the content of any one of the registers BX, BP, SI and DI in the default either DS or ES segment. e.g. MOV AX, 50HBX 7. Based Indexed: In this addressing mode, the effective address of the data is formed by adding the content of a base register (any one of BX or BP) to the content of an index register (any one of SI or DI). The default segment register may be ES or DS.e.gMOV AX, BX SI

8. Relative Based Indexed :The effective address is formed by adding an 8-bit or 16-bit displacement with the sum of contents of any one of the base register (BX or BP) and any one of the index registers in a default segment.e.g. MOV AX, 50HBXSI 9. Implied addressing mode:No address is required because the address or the operand is implied in the instruction itself. E.g NOP,STC,CLI,CLD,STD

Q. State any four examples of immediate addressing mode. (1/2 Marks for each) Ans.: Immediate addressing mode example are as 1) MOV AX, 0005H: AX is loaded with 16bitimmediate data i.e.0005H 2) MOV AL, 25H: Move 25H to AL or AL= 25H 3) MOV [SI], 0B29H – Move 0B29H (16 bit data) to two consecutive memory location which effective address or offset is in SI and base address is in DS. 4) MOV CX, 1234H: Move 16 bit data to CX or CX =1234H

Q. State the concept of pipelining of 8086. Ans.: concept of pipeline: (2 Mark) In pipelined processor, fetch, decode and execute operation are performed simultaneously or in parallel.

Page No.1

Page 2: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

When first instruction is being decoded ,same time next instruction‟s code is fetches. When first instruction is getting executed, second one‟s is decoded and third instruction code is fetches from memory. This process is known as pipelining. It improves speed of operation to great extent.

Q . If AL,BL and CL content 10H, 10H and 20H respectively .state the effects of following instructions i) CMP BL,CL ii) XCHG AL,CL Ans.: (2M each) AL 10H, BL 10H CL 20H i) CMP BL, CL: This instruction compares the source operand with a destination operand. For comparison, it subtracts the source operand from destination operand .i.e. it compare 20H TO 10 in above CL subtracted from BL I.E 20H from 10H ii) XCHG AL, CL: Exchange the content of CLTO AL i.e. 20H TO 10H (2 Mark)

f) Calculate physical address in the following cases: (2M each) i) CS: 1200H, IP:DE00H ii) DS: 1F00, BX:1A00 for MOV AX,[BX] Ans.: 1) Segment address ----1200H ------0001 0010 0000 0000 Offset address ------DE00H -----1101 1110 0000 0000 Segment address shifted by 4 bit position-0001 0010 0000 0000 0000 + 1101 1110 0000 0000 ----------------------------------------------------------- Physical address-----0001 1111 1110 0000 0000 1 F E 0 0 2) Segment address ----1F00H ------0001 1111 0000 0000

Offset address ------1A00H -----0001 1010 0000 0000 Segment address shifted by 4 bit position-0001 1111 0000 0000 0000 + 0001 1010 0000 0000 ----------------------------------------------------------- Physical address-----0010 0000 1010 0000 0000 2 0 A 0 0

Q. Compare the following instruction(2 Points) i. AND and TEST ii. AAA and DAA (each Point 1 Mark) i. AND and TEST AND TESTThe source and destination are ANDed and the result is stored in the destination.

The test instruction ANDs the source and the destination operands but does not store the result nor does it change the operands

The result in the destination after ANDing is used for further calculations.

This instruction is used to set the flags before conditional jump instructions.

Page No.2

Page 3: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

ii. AAA and DAA AAA DAAAAA stands for ASCII adjust after addition used in ASCII Addition.

DAA stands for Decimal adjust accumulator used in BCD addition

After the addition of ASCII equivalent of two decimal numbers, result is stored in AL register.

After the addition of two packed BCD numbers, the DAA instruction is used to adjust the hexadecimal result to its BCD equivalent.

Q. Explain following string instructions and respective prefix: i. REP MOV SW ii. REPE CMP SB Ans.: (2M each) i. MOVSW The MOVSW instruction is used to transfer a word from the source string to the destination string. The source must be in the data segment and the destination in the extra segment. The offset of the source word must be placed in SI register, which is represented as DS:SI and the offset of the destination word must be placed in DI register, which is represented as ES:DI On the execution of the instruction, SI and DI are automatically adjusted by one to the next element of the source and destination. If the Direction Flag is reset (DF = 0), the registers SI and DI will be incremented by two for the word movement. If the Direction Flag is set (DF = 1), the registers SI and DI will be decremented by two for the word movement. In multiple byte or word moves, the count must be loaded in CX register which functions as a counter. ii. REP (Instruction Prefix) The REP instruction prefix is used in string instructions and interpreted as “Repeat while not end of string” In REP prefix, CX register is loaded with the count. Operation performed :-- While CX <>0, perform the string operation CX CX - 1 iii. CMPSB The CMPSB instruction is used to compare a byte in the source string with a byte in the destination string. The source must be in the data segment and the destination in the extra segment. The offset of the source byte must be placed in SI register, which is represented as DS:SI and the offset of the destination byte must be placed in DI register, which is represented as ES:DI On the execution of the instruction, SI and DI are automatically adjusted by one to the next element of the source and destination.

Page No.3

Page 4: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

If the Direction Flag is reset (DF = 0), the registers SI and DI will be incremented by one for the byte comparison. If the Direction Flag is set (DF = 1), the registers SI and DI will be decremented by one for the byte comparison. In multiple byte or word comparison, the count must be loaded in CX register which functions as a counter. All conditional flags are affected

REPE/REPZ (Instruction Prefix) The REPE instruction prefix is used in string instructions and interpreted as “Repeat while not end of string and string equal” (CX<>0 and ZF =1) In REPE prefix, CX register is loaded with the count.

Operation performed :-- While CX <>0 & ZF -1 , perform the string operation CX CX - 1

Q. Identify the addressing modes used in the following instructions: i. MOV DS,AX ii. MOV AX, [4172H] iii. ADD AX, [SI] iv. ADD AX, [SI] [BX] [04H] Ans.: (Each Addressing Mode -1M) i) MOV DS,AX Mode : Register Addressing Mode ii) MOV AX, [4172H] Mode: Direct Addressing Mode iii) ADD AX, [SI] Mode: Register Indirect or Indexed Mode iv) ADD AX, [SI] [BX] [04H] Mode: Relative Based Indexed Mode

Q. Write appropriates 8086 instructions to perform following operations i. Initialize stack at 42000 H Ans. : (Instruction to initialize stack segment 1 mark, instruction to initialize stack pointer 1 mark) MOV AX,,4200h MOV SS,AX MOV SP,0000H ii. Rotate register BX right 4 times. (instruction to initialize counter 1 mark, rotate instruction 1 mark) MOV CL,04H RCR BX,CL or MOV CL,04H ROR BX,CL

Page No.4

Page 5: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

Q. List instruction formats of 8086 and explain any one.( 4 marks) Ans.: Machine Language instruction format: A machine language instruction format has one or more number of fields associated with it. The first field is called the opcode field, which indicate the type of operation performed by the CPU. The second field is called as an operand field which specifies the data on which the operation is to be performed. The general format of 8086 instruction with different fields is as given below. 8086 Instructions are represented as binary numbers Instructions require between 1 and 6 bytes.

This is the general instruction format used by the majority of 2-operand instructions. Bytes 1 and 2 are divided up into 6 fields: opcode d -direction (or s = sign extension) w -word/byte mod -mode reg -register r/m -register/memory opcode field specifies the operation performed (mov, xchg,etc) d (direction) field specifies the direction of data movement: d = 1 data moves from operand specified by R/M field to operand specified by REG field d = 0 data moves from operand specified by REG field to operand specified by R/M field W (word/byte) specifies operand size W = 1 data is word W = 0 data is byte

Page No.5

Page 6: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

Q. Identify addressing modes in following instructions:(i) MOV AX, 2050H(ii) STC(iii) MOV AL, DS:[SI](iv) INC BXAns: (Correct Addressing Mode 1 Mark each)(i) MOV AX,2050H -> Immediate Addressing mode(ii) STC -> Implied addressing mode(iii) MOV AL,DS:[SI] -> Indexed addressing mode(iv) INC BX -> Register addressing mode

Q. Write difference between the following instructions JNC 2000 H and JMP 2000 HAns: (Any 2 Correct Difference: 2 Mark each)JNC 2000H JMP 2000HConditional jump instruction Unconditional jump instructionJNC Causes short jump , aftercomparison if the condition is true,based on the current contents of the statusflag as carry flagJMP Causes IP to be modified so that thenext instruction is fetched from thelocation specified in code segmentAllows Short Jump to 2000H if Carryflag is set to 0.Allows to jump to location 2000Hwithout any flag checking.

Q. What will be content of register BX after execution of instructions?MOV BX, 2050HMOV CL, 05HSHL BX, CL(Correct answer : 4 Marks )For steps 1 M may be considered

Page No.6

Page 7: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

Content of BX After execution =0A00H

Q. Differentiate between following instructions:(i) ROL, RCL(ii) ADD, ADC(iii) MOV, LXI(iv) JMP, JNC( Any one Difference :1Mark)( Note: Third instruction is not a valid 8086 instruction; hence 1Mark may be given for attempting)

Page No.7

Page 8: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

Q. Describe various string instructions in brief.(Any 4 instructions (Operation or syntax) -1 Mark each)Ans:1] MOVS/ MOVSB/ MOVSW - Move String byte or word.Syntax: MOVS destination, sourceMOVSBMOVSW

Operation: ES:[DI]<----- DS:[SI]It copies a byte or word a location in data segment to a location in extra segment. The offset of source is pointed by SI and offset of destination is pointed by DI.CX register contain counter and direction flag (DF) will be set or reset to auto increment or auto decrement pointers after one move.

ExampleLEA SI, SourceLEA DI, destinationCLDMOV CX, 04HREP MOVSB3] CMPS /CMPSB/CMPSW: Compare string byte or Words.Syntax: CMPS destination, sourceCMPSBCMPSWOperation: Flags affected < ----- DS:[SI]- ES:[DI]It compares a byte or word in one string with a byte or word in another string. SI holds the offset of source and DI holds offset of destination strings. CX contains counter and DF=0 or 1 to auto increment or auto decrement pointer after comparing one byte/word.ExampleLEA SI, SourceLEA DI, destinationCLDMOV CX, 100REPE CMPSB

Page No.8

Page 9: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

4] SCAS/SCASB/SCASW: Scan a string byte or word.SyntaxSCAS/SCASB/SCASWOperation: Flags affected < ----- AL/AX-ES: [DI]It compares a byte or word in AL/AX with a byte /word pointed by ES: DI. The string to be scanned must be in the extra segment and pointed by DI. CX contains counter and DF may be 0 or 1.When the match is found in the string execution stops and ZF=1 otherwise ZF=0 .ExampleLEA DI, destinationMOV Al, 0DHMOV CX, 80HCLDREPNE SCASB5] LODS/LODSB/LODSW: Load String byte into AL or Load String word into AX.Syntax: LODS/LODSB/LODSWOperation: AL/AX < ----- DS: [SI]It copies a byte or word from string pointed by SI in data segment into AL or AX.CX may contain the counter and DF may be either 0 or 1ExampleLEA SI, destinationCLDLODSB

6] STOS/STOSB/STOSW (Store Byte or Word in AL/AX)Syntax STOS/STOSB/STOSWOperation: ES:[DI] < ----- AL/AXIt copies a byte or word from AL or AX to a memory location pointed by DI in extra segment CXmay contain the counter and DF may either set or reset.

Q .Explain stack operation. Why PUSH and POP instructions are used before and after CALL sub-routine?( PUSH and POP explanation each -1½ Marks, Reason - 1Mark)Ans : PUSH: push to stackThis instruction pushes the contents of the specified register/memory location on to the stack. The stack pointer is decremented by 2 after each execution of the instruction, to point the top element of the stack. The higher byte is pushed first and then the lower byte. Thus out of the two decremented stack addresses the higher byte occupies the higher address and the lower byte occupies the lower address.Example: PUSH AXPUSH DSPUSH [5000H] ; content of location 5000H and 5001H in DS are pushed onto thestack.POP: pop from stack

Page No.9

Page 10: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

This instruction when executed, loads the specified register/memory location with the contents of the memory location of which the address is formed using current stack segment and stack pointer as usual. The stack pointer is incremented by 2 to point the current stack top element.Example: POP AXPOP DSPOP [5000H] ;Reason:PUSH and POP instruction should be used before and after subroutine call to avoid data loss of all the register of CPU. Before subroutine call, all the registers’ content of the main program may be pushed onto the stack one by one using PUSH instruction into stack so that these registers can be used by subroutine. After subroutine execution, POP instruction should be used to get the old elements from the stack into the registers.Note: Number of PUSH and POP instruction should be equal.

Q. State any two example of immediate addressing mode and two example of direct addressing mode. Ans: (Each mode 2 examples: ½ Mark each) [NOTE- Any other valid example can be considered] Examples of immediate addressing mode: MOV AX , 0030H ADD AL, 20H Examples of direct addressing mode: MOV [3000H], AL AND BX, [2050H]

Q. Write assembly language instructions of 8086 microprocessor to (1) Divide the content of AX register by 50H (2) Rotate the content of BX register by 4 bit towards left Ans: (Correct Instruction: 1 Mark each) (1) Divide the content of AX register by 50H: MOV BL,50H DIV BL (2) Rotate the content of BX register by 4 bit towards left: MOV CL,04H ROL BX,CL OR MOV CL,04H RCL BX,CL

Page No.10

Page 11: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

Q. Explain DAA instruction with suitable example. Ans:- (Explain: 2 marks, example: 2marks) DAA – (Decimal Adjust AL after BCD Addition) Syntax- DAA Explanation: This instruction is used to make sure the result of adding two packed BCD numbers is adjusted to be a correct BCD number. The result of the addition must be in AL for DAA instruction to work correctly. If the lower nibble in AL after addition is > 9 or Auxiliary Carry Flag is set, then add 6 to lower nibble of AL. If the upper nibble in AL is > 9H or Carry Flag is set, and then add 6 to upper nibble of AL.Example: - (Any Same Type of Example) if AL=99 BCD and BL=99 BCD Then ADD AL, BL 1001 1001 = AL= 99 BCD + 1001 1001 = BL = 99 BCD ---------------------------------------- 0011 0010 = AL =32 H and CF=1, AF=1 After the execution of DAA instruction, the result is CF = 1 0011 0010 =AL =32 H AF =1 + 0110 0110 ------------------------- 1001 1000 =AL =98 in BCD (OR) Explanation: (DAA: Decimal Adjust Accumulator) This is the only instruction that uses the auxiliary flag to perform the binary to BCD conversion, and the conversion procedure is described below. S, Z, AC, P, CY flags are altered to reflect the results of the operation .If the value of the low-order 4-bits in the accumulator is greater than 9 or if AC flag

is set, the instruction adds 6 to the low-order four bits. If the value of the high-order 4-bits in the accumulator is greater than 9 or if the Carry flag is set, the instruction adds 6 to the high-order four bits. The DAA instruction (Decimal Adjust Accumulator) allows conversion of the 8-bit accumulator value to Binary Coded Decimal (BCD). If the low-order 4 bits of the accumulator are greater than 9, or the auxilliary carry flag is set, 6 is added to the low-order 4 bits of accumulator, then if the high-order 4 bits of the accumulator are greater than 9, or the carry flag is set, 6 is added to the high-order 4 bits of the accumulator. Execute DAA only after executing an ADD instruction that leaves a two-BCD-digit byte result in the AL register. The ADD operands should consist of two packed BCD

Page No.11

Page 12: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

digits. The DAA instruction adjusts AL to contain the correct two-digit packed decimal result. Example : mov al,38h ;packed decimal "38" add al,45h ;add packed decimal "45" daa ;AL = 7Dh -> 83h (with CF clear = 83 packed decimal) AL CF AF ; after addition 7Dh clear clear ; daa 1st part (al+6) 83h clear set (because al AND 0Fh > 9) ; daa 2nd part (nothing) 83h clear set (al !> 99h && CF clear)

Q. Explain any two string operation instructions with suitable example. Ans: (Any two each 2 marks)MOVSB / MOVSW: Move String Byte or String Word Suppose a string of bytes stored in a set of consecutive memory locations is to be moved to another set of destination locations. The starting byte of source string is located in the memory location whose address may be computed using SI (Source Index) and DS (Data Segment) contents. The starting address of the destination locations where this string has to be relocated is given by DI (Destination Index) and ES (Extra Segment) contents. CMPS: Compare String Byte or String Word The CMPS instruction can be used to compare two strings of byte or words. The length of the string must be stored in the register CX. If both the byte or word strings are equal, zero Flag is set. The REP instruction Prefix is used to repeat the operation till CX (counter) becomes zero or the condition specified by the REP Prefix is False.

SCAN: Scan String Byte or String Word This instruction scans a string of bytes or words for an operand byte or word specified in the register AL or AX. The String is pointed to by ES:DI register pair. The length of the string s stored in CX. The DF controls the mode for scanning of the string. Whenever a match to the specified operand, is found in the string, execution stops and the zero Flag is set. If no match is found, the zero flag is reset. LODS: Load String Byte or String Word The LODS instruction loads the AL / AX register by the content of a string pointed to by DS : SI register pair. The SI is modified automatically depending upon DF, If it is a byte transfer (LODSB), the SI is modified by one and if it is a word transfer (LODSW), the SI is modified by two. No other Flags are affected by this instruction.

STOS: Store String Byte or String Word

Page No.12

Page 13: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

The STOS instruction Stores the AL / AX register contents to a location in the string pointer by ES : DI register pair. The DI is modified accordingly; No Flags are affected by this instruction. The direction Flag controls the String instruction execution, the source index SI and Destination Index DI are modified after each iteration automatically. If DF=1, then the execution follows auto decrement mode, SI and DI are decremented automatically after each iteration. If DF=0, then the execution follows auto increment mode. In this mode, SI and DI are incremented automatically after each iteration.

Q. Identify the addressing mode of following instructions. (i) INC [4712H] (ii) ADD AX, 4712H (iii) DIV BL (iv) MOV AX, [BX + SI] Ans: (each 1 mark) (i) INC [4712H] :Direct Addressing Mode (ii) ADD AX, 4712H :Immediate Addressing Mode (iii) DIV BL :Register Addressing Mode (iv) MOV AX, [BX + SI] :Base Plus Index Mode (OR) Based Indexed Addressing Mode

Q. Write an instruction of 8086 to perform following operation. (i) Shift the content of BX register'3 bit toward left. (ii) Move 1234H in DS register. Ans: (Each 2 marks) (i) Shift the content of BX register'3 bit toward left : MOV CL, 03H SHL BX, CL (OR) MOV CL,03H SAL BX,CL (ii) Move 1234H in DS register MOV AX, 1234H MOV DS, AX

Q. Explain the following instructions of 8086 with suitable example. (i) LOOP (ii) INT D Ans: (Description -1 Marks, Example -1 Marks)(i) LOOP:

Page No.13

Page 14: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

The LOOP instruction is a combination of a decrement of CX and a conditional jump. In the 8086, LOOP decrements CX and if CX is not equal to zero, it jumps to the address indicated by the label. If CX becomes a 0, the next sequential instruction executes. Example: MOV BX, OFFSET PRICES Point BX at first element in array MOV CX, 40 Load CX with number of elements in array NEXT: MOV AL, [BX] Get element from array INC AL Increment the content of AL MOV [BX], AL Put result back in array INC BX Increment BX to point to next location LOOP NEXT Repeat until all elements adjusted (ii) INT D (INT IMMEDIATE BYTE):

Interrupt numbered by immediate byte (0..255). Flags Affected IF=0, CY,P,A,Z,S,O - unchanged Algorithm: Push to stack Flags register CS IP IF = 0 Transfer control to interrupt procedure Example: MOV AH, 0Eh ; teletype. MOV AL, 'A' INT 10h ; BIOS interrupt. RET

Q. Explain CALL and RET instructions with suitable example. Write syntax of CALL and RET instructions. Ans: (Description -1 Marks, Example -1 Marks) [Note: Any Suitable Example can be considered] CALL Instruction: It is used to transfer program control to the sub-program or subroutine. The CALL can be NEAR, where the procedure is in the same segment whereas in FAR CALL, procedure is in a different segment. Syntax: CALL procedure name (direct/indirect) Operation: Steps executed during CALL Example: 1) For Near CALL SP SP - 2 Save IP on stack IP address of procedure 2) For Far call

Page No.14

Page 15: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

SP SP-2 Save CS on stack CS New segment base containing procedure SP SP-2Save IP on stack IP Starting address of called procedure RET instruction: it is used to transfer program execution control from a procedure to the next instruction immediate after the CALL instruction in the calling program. Syntax: RET Operation: Steps executed during RET Example: 1) For Near Return IP Content from top of stack SP SP + 2 2) For Far Return IP Contents from top of stack SP SP+2 CS Contents of top of stack SP SP+2

Q .What will be contents to AX register after execution of following lines of code:MOV AL, 10MOV DL, 20MUL DL(Correct answer – 4 Marks)

Ans: AH AL 00 C8ORAX = 00C8H

Q. Write any two arithmetic instructions & logical instructions with their functions. Give thesyntax with one example each.(For each instruction, syntax -1 Mark, Example – 1 Mark)Ans:Any two arithmetic instructions from the following or any other1. ADD Destination, SourceExample:ADD AL, 74H

Page No.15

Page 16: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

ADD DX, AXADD AX, [BX]2. ADC Destination, SourceExample:ADC AL, 74HADC DX, AXADC AX, [BX]3. SUB Destination, SourceExample:SUB AL, 74HSUB DX, AXSUB AX, [BX]4. SBB Destination, SourceExample:SBB AL, 74HSBB DX, AXSBB AX, [BX]5. INC DestinationExample:INC AXINC BL6. DEC DestinationExample:DEC AXDEC CL7. MUL (Unsigned multiplication)Syntax: MUL sourceExamples:1. MUL BL ; Multiply AL by BL & the result in AX2. MUL CX ; Multiply AX by CX & the result in DX,AX3. MUL Byte PTR [SI] ; AX AL * [SI]8. IMUL (Signed multiplication)Syntax: IMUL sourceExample:1. IMUL BL ; Multiply AL by BL & the result in AX2. IMUL CX ; Multiply AX by CX & the result in DX,AX3. IMUL Byte PTR [SI] ; AX AL * [SI]9. DIV (Unsigned Division)Syntax: DIV sourceExamples:1. DIV BL ; Divide word in AX by byte in BL, Quotient is stored in AL,remainder in AH.2. DIV CX ; Divide double word in DX:AX by word in CX, Quotient in AX,Remainder in DX

3. DIV [BX] ; Divide word in AX by byte in memory location pointer by BX.

Page No.16

Page 17: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

Any two logical instructions from the following or any otherAND (Logical AND)Syntax: AND destination, sourceExamples:1. AND BH,CL ;AND byte in CL with Byte in BH, result in BH.2. AND BX,00FFH ;AND word in BX with immediate data 00ffH3. AND [5000H], DX ;AND word in DX with a word in memory with offset 5000 in DS.OR (Logical OR)Syntax: OR destination, sourceExamples:1. OR BH,CL ;OR byte in CL with Byte in BH, result in BH.2. OR BX,00FFH ;OR word in BX with immediate data 00ffH3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS.XOR (Logical XOR)Syntax: XOR destination, sourceExamples:1. XOR BH,CL ;XOR byte in CL with Byte in BH, result in BH.2. XOR BX,00FFH ;XOR word in BX with immediate data 00ffH3. XOR [5000H], DX ; XOR word in DX with a word in memory with offset 5000 in DS.NOT (Logical Invert)Syntax: NOT destinationExamples:1. NOT BH ;Complement byte in BH, result in BH.2. NOT BX ; Complement word in BX, result in BX.3. NOT BYTE PTR [5000H] ; Complement byte in memory with offset 5000 in DS.

List & explain any four string operation instructions with their functions & syntax.(Each instruction operation -1 Mark, only listing - 1 Mark will be considered)Ans: 1] REP: REP is a prefix which is written before one of the string instructions. It will cause duringlength counter CX to be decremented and the string instruction to be repeated until CX becomes0.Two more prefix.REPE/REPZ: Repeat if Equal /Repeat if Zero.It will cause string instructions to be repeated as long as the compared bytes or words are equaland CX≠0.REPNE/REPNZ: Repeat if not equal/Repeat if not zero.It repeats the strings instructions as long as compared bytes or words are not equal and CX≠0.Example: REP MOVSB2] MOVS/ MOVSB/ MOVSW - Move String byte or word.

Page No.17

Page 18: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

SyntaxMOVS destination, sourceMOVSB destination, sourceMOVSW destination, sourceOperation: ES:[DI]<----- DS:[SI]It copies a byte or word a location in data segment to a location in extra segment. The offset ofsource is pointed by SI and offset of destination is pointed by DI.CX register contain counter anddirection flag (DE) will be set or reset to auto increment or auto decrement pointers after onemove. ExampleLEA SI, SourceLEA DI, destinationCLDMOV CX, 04HREP MOVSB

3] CMPS /CMPSB/CMPSW: Compare string byte or Words.SyntaxCMPS destination, sourceCMPSB destination, sourceCMPSW destination, sourceOperation: Flags affected < ----- DS:[SI]- ES:[DI]It compares a byte or word in one string with a byte or word in another string. SI holds the offsetof source and DI holds offset of destination strings. CS contains counter and DF=0 or 1 to autoincrement or auto decrement pointer after comparing one byte/word.ExampleLEA SI, Source5] LODS/LODSB/LODSW: Load String byte into AL or Load String word into AX.Syntax: LODS/LODSB/LODSWOperation: AL/AX < ----- DS: [SI]IT copies a byte or word from string pointed by SI in data segment into AL or AX.CX maycontain the counter and DF may be either 0 or 1ExampleLEA SI, destinationCLDLODSB6] STOS/STOSB/STOSW (Store Byte or Word in AL/AX)Syntax STOS/STOSB/STOSWOperation: ES:[DI] < ----- AL/AXIt copies a byte or word from AL or AX to a memory location pointed by DI in extra segment CX

Page No.18

Page 19: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

may contain the counter and DF may either set or reset.LEA DI, destinationCLDMOV CX, 100REPE CMPSB4] SCAS/SCASB/SCASW: Scan a string byte or word.SyntaxSCAS/SCASB/SCASWOperation: Flags affected < ----- AL/AX-ES: [DI]It compares a byte or word in AL/AX with a byte /word pointed by ES: DI. The string to bescanned must be in the extra segment and pointed by DI. CX contains counter and DF may be 0or 1.When the match is found in the string execution stops and ZF=1 otherwise ZF=0 .ExampleLEA DI, destinationMOV Al, 0DHMOV CX, 80HCLDREPNE SCASB

Q . Identify the addressing modes of following instructions:(i) MUL AL, BL (ii) MOV AX, BX (iii) MOV BX, [S1] (iv) MOV DX, 0040H(Each addressing mode - 1 Mark each)Ans:i) MUL AL,BL:- Register addressing modeii) MOV AX ,BX:- Register addressing modeiii) MOV BX,[SI]:-Indexed addressing modeiv) MOV DX,0040H:-Immediate addressing mode

Q . Explain the following instructions of 8086 microprocessor with their syntax:(i) STRCMP (ii) ADD(Each – 2 Marks)Ans: (i) STRCMP:-(There is no instructions such as STRCMP. Instead, CMPS instruction may be considered as given below CMPS/CMPSB/CMPSWSyntax : CMPS destination, sourceCMPSB

CMPSW• The CMPS instruction is used to compare a byte or a word in the source string with a byte or aword in the destination string.• The source must be in the data segment and the destination in the extra segment.• The offset of the source byte or a word must be placed in SI register, which is represented as DS:SI and the offset of the destination byte or a word must be placed in DI register, which is represented as ES:DI

Page No.19

Page 20: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

• On the execution of the instruction, SI and DI are automatically adjusted by one to the next element of the source and destination.• If the Direction Flag is reset (DF = 0), the registers SI and DI will be incremented by one for the byte comparison and incremented by two for the word comparison.• If the Direction Flag is set (DF = 1), the registers SI and DI will be decremented by one for thebyte comparison and decremented by two for the word comparison• The DS:SI and ES:DI register must be loaded prior to the execution of the CMPS instruction.• CMPSB and CMPSW are the implicit instructions to move a byte or word string .• The instruction CMPSB is used to compare a byte from the source with destination and the instruction CMPSW is used to compare a word in the source with destination.• In multiple byte or word comparison, the count must be loaded in CX register which functions as a counter.• All conditional flags are affectedOROperation Performed :--If dest string > source string then CF =0, ZF = 0, SF = 0If dest string < source string then CF =1, ZF = 0, SF = 1If dest string = source string then CF =0, ZF = 1, SF = 0If a byte comparison,For DF =0, SI SI +1 & DI DI +1For DF =1, SI SI -1 & DI DI – 1If a word comparison,For DF =0, SI SI +2 & DI DI +2For DF =1, SI SI -2 & DI DI – 2

(iii) ADD:-This instruction is used to add immediate data to contain of register or to add content of one register (or memory location )to another register (or memory location )Syntax:- ADD destination, sourceDestination may be register or memory location and source may be data, memory location’s or registers.

Q.Write an assembly language instructions to perform following operations:(i) Move contents of memory location pointed by DI into BX register.(ii) Copy a string from one memory location to another using string manipulationinstruction.(Each instructions – 2 Marks)Ans:

i) MOV BX,[DI] ii) ii) MOV DS,SOURCE_ST

MOV ES,DEST_STCLD (OPTIONAL)MOVSB

Page No.20

Page 21: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

Q .Identify the addressing modes in following instructions(i) MUL AL, BL(ii) MOV AX, 2100 H(iii) MOV AL, DS : [SI](iv) MOV AX, BX.(Each addressing mode - 1 Mark each)Ans:i) MUL AL,BL:- Register addressing mode (Incorrect MUL instruction; corrected as MUL BL)ii) MOV AX ,BX:- Register addressing modeiii) MOV AX,2100H:-Immediate addressing modeiv) MOV AL,DS:[SI] :-Indexed addressing mode

Q. State and explain any four addressing modes of 8086 microprocessor with example.(Each Addressing mode -1 Mark)Ans : Addressing modes of 8086:1. Immediate addressing mode:An instruction in which 8-bit or 16-bit operand(data ) is specified in the instruction, then the addressing mode of such instruction is known as Immediate addressing mode.Example:MOV AX,67D3H2. Register addressing mode:An instruction in which an operand(data) is specified in general purpose registers, then the addressing mode is known as register addressing mode.Example:MOV AX,CX3. Direct addressing mode:An instruction in which 16 bit effective address of an operand is specified in the instruction, then the addressing mode of such instruction is known as direct addressing mode.Example:MOV CL,[2000H]4. Register Indirect addressing mode:An instruction in which address of an operand is specified in pointer register or in index register or in BX, then the addressing mode is known as register indirect addressing mode.Example:MOV AX, [BX]5. Indexed addressing modeAn instruction in which the offset address of an operand is stored in index registers (SI or DI) then the addressing mode of such instruction is known as indexed addressing mode.DS is the default segment for SI and DI.For string instructions DS and ES are the default segments for SI and DI resp.this is a special case of register indirect addressing mode.Example: MOV AX,[SI]6. Based Indexed addressing mode:an instruction in which the address of an operand is obtained by adding the contents of base register (BX or BP) to the content of an index register (SI or DI) The default segment register may be DS or ES

Example : MOV AX, [BX][SI]

Page No.21

Page 22: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

7. Register relative addressing mode:An instruction in which the address of the operand is obtained by adding the displacement (8-bit or 16 bit) with the contents of base registers or index registers (BX, BP, SI, DI). the default segment register is DS or ESExample:MOV AX, 50H[BX]8.Relative Based Indexed addressing mode:An instruction in which the address of the operand is obtained by adding the displacement (8 bit or 16 bit) with the base registers(BX or BP) and index registers (SI or DI) to the default segment.Example:MOV AX, 50H [BX][SI]

Q . Explain the following instructions of 8086(i) DAA (ii) XLAT (Each instruction explanation - 2 Marks)Ans:(i) DAA (Decimal Adjust Accumulator):Syntax :-- DAA• This instruction is used to convert the result of the addition of two packed BCD numbers to a valid BCD number.• The result has to be only in AL.• After addition if the lower nibble is greater than 9 or AF =1, it will add 06H to the lower nibble in AL.• After this addition, if the upper nibble is greater than 9 or if CF = 1, DAA instruction adds 60H to AL.• DAA instruction affects AF,CF,PF and ZF. OF is undefined.(ii) XLAT• XLAT : translate– Can be used for look up table– Default source & destination operand is AL– Default base address of look up table is in BX– Physical address in look up table = 10H * DS + AL + BX– Example:MOV AL, NUM; read the number

MOV BX, OFFSET_TABLE; store the base address of look up tableXLAT

Q . List the string related instructions of 8086 microprocessor and explain any two instructions.(List - 2 Marks, explanation of any two instructions – 2 Marks)Ans:String related instructions of 8086 microprocessor are:1. MOVS 2. MOVSB. 3. MOVSW. 4. LODS. 5. LODSB 6. LODSW7. STOS 8. STOSB 9. STOSW 10. CMPS 11. CMPSB 12. CMPSW13. SCAS 14. SCASB 15. SCASW1] MOVS/ MOVSB/ MOVSW - Move String byte or word.Syntax :MOVS destination, sourceMOVSBMOVSWOperation: ES:[DI]<----- DS:[SI]

Page No.22

Page 23: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

It copies a byte or word a location in data segment to a location in extra segment. The offset of source is pointed by SI and offset of destination is pointed by DI.CX register contain counter and direction flag (DF) will be set or reset to auto increment or auto decrement pointers after one move.ExampleLEA SI, SourceLEA DI, destinationCLDMOV CX, 04HREP MOVSB3] CMPS /CMPSB/CMPSW: Compare string byte or Words.

Syntax:CMPS destination, sourceCMPSBCMPSWOperation: Flags affected < ----- DS:[SI]- ES:[DI]It compares a byte or word in one string with a byte or word in another string. SI holds the offset of source and DI holds offset of destination strings. CX contains counter and DF=0 or 1 to auto increment or auto decrement pointer after comparing one byte/word.ExampleLEA SI, SourceLEA DI, destination

CLDMOV CX, 100REPE CMPSB4] SCAS/SCASB/SCASW: Scan a string byte or word.Syntax: SCAS/SCASB/SCASWOperation: Flags affected < ----- AL/AX-ES: [DI]It compares a byte or word in AL/AX with a byte /word pointed by ES: DI. The string to be scanned must be in the extra segment and pointed by DI. CX contains counter and DF may be 0 or 1. When the match is found in the string execution stops and ZF=1 otherwise ZF=0 .ExampleLEA DI, destinationMOV Al, 0DHMOV CX, 80HCLDREPNE SCASB5] LODS/LODSB/LODSW: Load String byte into AL or Load String word into AX.Syntax: LODS/LODSB/LODSWOperation: AL/AX < ----- DS: [SI]It copies a byte or word from string pointed by SI in data segment into AL or AX.CX may contain the counter and DF may be either 0 or 1ExampleLEA SI, destination

Page No.23

Page 24: thegratesyco.files.wordpress.com · Web view2017/03/03  · 3. OR [5000H], DX ; OR word in DX with a word in memory with offset 5000 in DS. XOR (Logical XOR) Syntax: XOR destination,

Chapter 3

CLDLODSB6] STOS/STOSB/STOSW (Store Byte or Word in AL/AX)Syntax STOS/STOSB/STOSWOperation: ES:[DI] < ----- AL/AXIt copies a byte or word from AL or AX to a memory location pointed by DI in extra segment CX may contain the counter and DF may either set or reset.

Q . Write the appropriate 8086 instructions to perform the following operation.(i) Multiply AL register contents by 4 using shift instructions.(ii) Move 2000 H into CS register.

( (i) Correct instructions – 2 Marks )( (ii) Examiner can give marks if question is attempted.)Ans:I)MOV CL,02HSHL AL,CLII)The contents if CS register cannot be modified directly , Hence no instructions are usedHowever examiner can give marks if question is attempted.

Page No.24