Hot Posts

MALP UNIT 2 (QUESTION BANK)

UNIT 02    
 
ALEART:- Dear Valued Audience, I want to extend my sincerest apologies for the recent increase in advertisements on our platform. Due to some technical issues, the ad code was inadvertently placed in a way that led to an excessive number of ads being displayed. I understand how frustrating this must have been, and I am truly sorry for any inconvenience it caused. We are working diligently to resolve the issue and restore a better browsing experience for you. Thank you for your patience and understanding. Warm regards, VMSTUDYPOINT (TRY TO CLOSE ADS IN CORNER )
1] Explain Addressing Modes of 8086 in detail. (7 M)
                                      
OR
What do you mean by addressing modes? Explain with example various memory operand addressing modes.    (7 M)
OR
Explain the following addressing modes of 8086.
i)  Direct addressing mode.
ii) Based Index addressing mode. iii) Index addressing mode. (6 M)
 
Ans : When the instructions are executed in 8086 ,it performs on the specified data i.e. Operand . the operand may me resides in the one of the internal register of the microprocessor, may be stored at an address in memory, to access this  different types of operand, the 8086 is provided with various Addressing Modes. Addressing modes indicates a way of locating data or operands. The addressing modes are classified into basic three types :

1)    Register operand addressing 
2)    Immediate operand addressing
3)    Memory operand addressing
 
1) Register Operand Addressing :   
The operand to be accessed is specified as residing in an internal registers of 8086.( The instruction performed on the operands are stored in the registers.) Operand may be byte or word.
e.g.  MOV AX , BX
In the above instruction the operand is stored in the register BX (source) which has to be move to the register AX (destination).

2) Immediate Operand Addressing : 
If an operand is a part of the instruction instead of the contents of the register or memory location, that operand is said to immediate operand (operand is directly given in instruction.) And the addressing mode use for these operands are immediate addressing mode. The operand may be byte or word.
e.g.  MOV  AL , 15H
In the above instruction the operand 1516 (source) is immediate operand which has to be move to the lower byte of AH register i.e. AL(destination) 

3) Memory Operand Addressing :  
To an operand in the store in the memory and to fetch that address we need to calculate the effective address(EA). This addressing mode consist of the different representation of the EA. The memory operand addressing is further divided into following parts:

1] Direct Addressing Mode :  
In this addressing mode the 16-bit EA is taken directly from the displacement field of the instruction. The displacement (unsigned 16-bit or signed-extended 8-bit number ) is stored in the location following the instruction.
E.g. Mov AL , [3000H] : here 3000H is the offset address and by default the content of Data Segment will be segment address . The combination of these two addresses having the address of particular memory location that content some data which is moved to AL register.

2] Register Indirect Addressing Mode :   
In this mode, the EA is specified in either a pointer register or an index register. The pointer register can be either base register (BX) or base pointer(BP) and the index register can be either source index (SI) or destination index (DI). The physical address is computed by using DS and EA .
e.g. MOV [DI] , BX : The instruction copied the 16-bit content of BX into the memory location offset by the value of EA specified in the DI from the current contents in DS. Now , if we consider [DS]=7205H , [DI]= 0030H and BX = 8765H, the after execution of instruction , the content of BX is copied to the memory locations 72080H and 72081H
Physical Address: [DS]x [10H]+EA = [DS]x [10H] + [DI]

3] Base Addressing Mode :  
In this addressing mode , the effective address of the operand is obtained by adding a direct or indirect displacement to the contents of either base register(BX) or base pointer (BP). To find the actual physical address this displacement is also added to the segment address and offset address.
e.g. MOV AX , [BP + 6] : If the content of BP =2300H and SS=1000H then the content of memory locations 12306H and 12307H will move to the 16-bit  destination register AX

4] Index Addressing Mode :  
This addressing mode uses only one of the two index registers (SI or DI) and the 8-bit or 16-bit displacement is included in the operand field. To find the actual physical address this displacement is also added with segment address and offset address.
e.g. MOV AX , [SI + 16] : If the content of SI=1400H and DS =4000H then the contents of memory locations 41416H and 41417H are move to the 16-bit destination Register AX.

5] Base Index Addressing Mode : 
This addressing Mode combines the features of the Base Addressing Mode and Index Addressing Mode but does not allow the use of a displacement . Two registers must be used as source and destination operand , one for BX/BP or another for SI/DI. This combination of two register can be written as [BX][DI] or [BX+DI] both have the same meaning and gives the total offset value with addition of these registers.
e.g. MOV [BP][SI] , AL : If the content of SS=0400H , BP= 4320H and SI= 4000H and AL = 34H is given the physical address will be calculated as SS*10H+BP+SI so 04000H+4320H+4000H = 0C320H, the content of AL register will be load at 0C320H memory location .
 
2] Explain following instruction :
     1) DAS   2) SBB   3) XALT    4) DAA
     5)ADC   6) SUB    7) IMUL   8) LDA / LES   
    10) XCHG   11) IN   (each for 3M/4M) 
Ans :  
1) DAS :  
             This instruction is decimal adjust after subtraction is similar to DAA instruction except that this adjusts decimal result after subtraction .This instruction internally performs following steps :
Step 1: Check lower nibble of AL;
                          If it is greater than 9, 
                                        Subtract  6 to this nibble.
                          Else 
                                        No change.

Step 2: Check upper nibble of AL:
                           If it is greater than  9,
                                       Subtract  6  to this nibble 
                           Else 
                                       No change.

Example :  
                  MOV AL ,10       ; AL = 10H
                  SUB AL , 3         ;  AL = 10H – 3H will give result 0DH in AL.
                  DAS                   ; because lower nibble is greater than 9,                                                                                                      ;   subtracted by 6 , will give result 7.
                                              ;   upper nibble is zero , so on change.
                            Finally 
                                              ; AL = 07 . This is our result.  

2)SBB : 
          The operation of SBB is similar to SUB. However in subtraction to the source operand the processor also subtract the content of carry flag.
It is primarily used for multiword subtract operation.
Destination = Destination – Source – Carry
Syntax :  SBB Destination , Source
Example : SBB BX , CX 
                    If the contents of BX=1234H and contents of CX=0123H then after execution the result i.e. content of BX=1111H carry flag will remain unset as no borrow is taken. 
                       
3)XALT :
                  This instruction converts the content of the AL registers into a number stored in a memory table. This instruction performs the direct table lookup techniques, which is often used to convert one code to another .An XLAT instruction first adds the content of AL to BX to form a memory address within the data segment . It copies the content of this address into AL. This is the only instruction that adds the 8-bit number to a 16-bit number. Syntax : XLAT
Example :  Suppose a translation table resides at address 2000H (contents of BX registers ) and AL=05H and DS=4000H then the working of XLAT instruction will check the memory location of the address DS * 10H + BX + AL i.e. 42005H which contains 8AH then the AL=8AH. 

4)DAA :
              Sometimes we need to add decimal numbers together and assumes results as decimal , but processor solves numbers treating as a hexadecimal numbers so it is not always possible to get correct decimal result after addition . For example we want to add 23 and 18, processor will treat these numbers as hexadecimal numbers and gives answer 3BH , which is not correct answer form our respect , so DAA instruction is able to correct this instruction adjust only lower byte of AX. This instruction internally performs following steps :
Steps1: Check lower nibble of AL ;
                        If it is greater than 9, 
                            Add 6 to this nibble . Auxiliary carry will be set.
                        Else
                            No change . Auxiliary carry will be clear.
Step 2 : Check upper nibble of AL :
                        If it is greater than 9,
                                Add 6 to upper nibble with Auxiliary carry
                        Else 
                                Add upper nibble with Auxiliary carry.
 
Syntax : DAA
Example : ADD AL , BL
                  DAA

5) ADC : 
                 The operation of ADC is similar to ADD .However , in addition to the source operand the processor also add contents of the carry flag . The ADC is commonly used to add multi-bytes together ,  basically more than storage capacity. Destination = Destination + Source + Carry
Syntax : ADC Destination, Source
Example : Suppose we want to perform 32-bit operation , but we have 16-bit register in 8086,so we can store only 16-bit in any register. Consider AX store lower 16-bit number AC59H . Now add the contents of AX register with 9678H , which will give result 42D1H and carry flag will be set 
                    Now , our aim is to add upper 16-bit numbers (7654H + 24447H) and we have to add carry too these numbers to get correct result. This operation can not be performed by simple ADD instruction , so we need a new instruction which will add the operands as well as carry , hence this instruction.   

6)  SUB :  
               This instruction is used to subtract 8-bit(byte) or 16-bit (word) operands together. If source operand is larger than the destination operand , the resulting borrow is indicating by setting carry flag. 
Syntax : SUB Destination , Source 
Example :  SUB AX , BX 
                    If AX=1234H and BX= 4321H the after the execution of instruction the AX will be CF13H and carry flag will be set to indicate borrow was taken. 
   
7)  IMUL : 
                 This instruction is similar to MUL expert that operands are assumed to be a signed numbers. The source operand specified in the instruction is multiplied by accumulator , if source is 8-bit it multiplies with AL and result is placed into AX register. If source is 16-bit then it multiplies with Ax register and result is placed into DX : Ax registers
Syntax : IMUL Source   
Example : IMUL  BL If AL =80H and BL=20H, The content of AL will be treated as signed number which is 2’s complement of (128)10 which is -128 * 32 then multiplication of these numbers is -4096 , the 2’s complement of this number is F000H . So finally AX will be F000H.

8)  LDS / LES :
                             These instruction are used to load two 16-bit registers from a 4-byte block of memory . The first two bytes are copied into destination registers and the next two bytes are copied into corresponding segment registers DS / ES . These instruction are useful when we want to load segment and offset value by using single instruction. Usually in string instruction we use the instruction to load source string address (DS:SI) and destination string address (ES:DI) using single instruction
Syntax : LDS / LES Destination , Source  
Example : LEA SI , EA   When executed it loads the SI register with the offset address value. The value of this address is represented by the effective address EA. The value of effective address can be specified by any valid addressing mode. For instance , if the value in DI equals 1000H and that in BX is 20H , then executing the instruction
                   LEA SI , [DI + BX + 5H] Will load SI with the value (SI)= 1025H     

9)       XCHG :   
                     This instruction is used to swap the data . After executing this instruction destination and source will swap . 
Syntax : XCHG Destination , Source
Example : XCHG AL , BL  If AL = 34H and BL= 76H then after execution AL will be 76H and BL=34H. 

10)  IN :
              Processor has a separate I/O space from its memory space . among them 65536 I/O ports available for the programmer to use.
              These  ports can be access directly , using the ports address , for 65536 ports address in 0000H to FFFFH , the input port is actually a hardware device connected to the processor’s port . The 8086 allows two different forms of the IN instruction. A fyll 16-bit ports address must be loaded into DX register and instruction like IN Al , DX or IN AX , DX may be used to read the input port . If the port number is in between 00H to FFH then another form of IN instruction may be used as In AL , 86H or IN AX , 80H.
Syntax : IN accumulator , port
Example : If we want to read input 80 H then we may give instruction like 
             IN AL , 08 H   or    MOV DX , 80H 
                                             IN AL , DX 
 
3] Explain Instruction format of 8086.
Ans :
 •A machine language instruction format has one or more number of fields associated with it. 
•The first field is called as operation code field or op-code field, which indicates the
 type of operation to be performed by the CPU
•The instruction format also contains other fields known as operand fields
•The CPU executes the instruction using the information which reside in these fields
•There are six general formats of instructions in 8086 instruction set.
•The length of an instruction may vary from 1 byte to 6 bytes. The instruction formats
are described as follows

1] One Byte Instruction:

•This format is only one byte long and may have the implied data or register operands.
•The least significant 3-bits of the opcode are used for specifying the register operand, if any
•Otherwise, all the 8 bits form an opcode and the operands are implied 2] Register to Register:
•This format is 2 bytes long
•The first byte of the code specifies the operation code and width of the operand specified by ‘w’ bit.
•The second byte of the code shows the register operands and R/M field, as shown below:  
One Byte Instruction

•The register represented by the REG field is one of the operands.

•The R/M field specifies another register or memory location i.e. the other operand.

 

3]  Register to/from memory with no displacement:

•This format is also 2 bytes long and similar to the Register to Register format except for the MOD field as shown.

 

Register to/from memory with no displacement:

•The MOD field shows the mode of addressing. The MOD, R/M, REG and the ‘W’ fields are decided in Table 2.2.


4]  Register to/from Memory with Displacement: 

•This type of instruction format contains 1 or 2 additional bytes for displacement along with 2 byte format of the register to/from memory without displacement. The format is as shown below. 

Register to/from Memory with Displacement:

5]  Immediate Operand to Register:

•In this format, the first byte as well as the 3-bits from the second byte which are used for REG field in case of register to register format are used for opcode.

•It also contains one or two bytes of immediate data. The complete instruction format is as shown below. 

Immediate Operand to Register:

3]  Immediate Operand to Memory with 16-bit displacement:

•This type of instruction format requires 5 or 6 bytes for coding.

•The first 2 bytes contain the information regarding OPCODE, MOD and R/M fields.

The remaining 4 bytes contain 2 bytes of displacement and 2 bytes of data as shown. 

Immediate Operand to Memory with 16-bit displacement:

4] State and Explain Arithmetic group of Instruction.

Ans :The  operation such as Addition , Subtraction , Multiplication and Division are the arithmetic . To perform these operation the 8086 is provided with the arithmetic group of instruction which consist of following instruction :

Addition :

1]  ADD : This instruction is use to perform addition of two 8-bit or 16-bit      registers or immediate operand 

e.g. ADD AX , BX  

2]  ADC : This instruction is use to perform addition of two 8-bit or 16-bit      registers or immediate operand and the content of carry flag are added to the result if it is set.

e.g. ADC AX , BX

3]  INC : The instruction increases the operand by one 

e.g. INC AX 

4]  AAA: After performing the addition of the ascii values the result is adjust by ascii to get the required output. This instruction is used after ADD instruction  e.g.  ADD AX , BX

         AAA

5]  DAA : The instruction is performed on the packed BCD numbers after performing operation the     result is adjust with the decimal. It is used after ADD instruction. 

        e.g. ADD AL , BL 

        DAA 

 

Subtraction : 

1]  SUB : This instruction is used to subtract two operand representing in an form of addressing modes .e.g. SUB AX , BX  

2]  SBB :  After performing the subtraction of the if the borrow is taken then the  carry  flag is set . So, the content of carry flag are also subtracted from the result.

     e.g. SBB AL , BL

3]  DEC : The decrease the operand by 1 .

      e.g. DEC AL 

4]  AAS : After performing the subtraction of the ascii values the result is adjust by ascii to get the required output. This instruction is used after SUB instruction.

      e.g. SUB AL , BL 

        AAS 

5]  DAS : The instruction is performed on the packed BCD numbers after performing operation the result is adjust with the decimal. It is used after SUB instruction.

        e.g. SUB AL , BL 

        DAS

6]  NEG : The operand is convert to its 2’s complement  

        e.g. NEG AL 

 

Multiplication / Division :

1]  MUL :  It multiplies the two unsigned integer values, one of the operand always resides in the AX register. 

        e.g. MUL BL 

2]  IMUL : It multiplies the two signed integer values, one of the operand always resides in the AX register.

        e.g. IMUL BL 

3]  AAM : It adjust the AX register for multiplication 

4]  DIV : 1] MUL :  It divide the two unsigned integer values, one of the operand always resides in the AX register. 

        e.g. DIV BL 

5]  IDIV :  It divides the two signed integer values, one of the operand always resides in the AX register.

        e.g. IDIV BL 

6]  AAD : It adjust the AX register for division.

7]  CBW : It convert the Byte value to the Word value i.e. 8-bit to 16-bit 8] CWD : It convert the word to the double word i.e. 16-bit to 32-bit

        e.g. MOV AL , 0A1H

        CBW

        CWD


5] Assume that (AX)=001016 , (BX)=010016 and (DS)=100016, What happens if XLAT instruction is executed?

Ans : Given,

                      (AX) = 001016   

                      (BX) = 010016                       (DS) = 100016

Hence lookup table resides at   DS x 10                            i.e.          10000H

                                                       + BX                                           0100H

                                                                                                          10100H

So the lookup table is at the address 10100H . The value of the AL=10H.The data from the memory location will transfer to the AL register.


6] Assume that (AX)=110016 , (BX)=0ABC16. What is the result of executing instruction ADD AX,BX?

Ans : 

         Given, 

                      (AX)= 110016

                      (BX)= 0ABC16

        Instruction : ADD AX, BX

The content of register AX and BX are added and the result is stored in the AX register 

(AX) = 110016 = 0001000100000002  

ADD

(BX) = 0ABC16 =0000101010111100 2

(AX) =1BBC 16= 00011011101111002

Hence after executing the instruction the result stored in the AX is 1BBC16.

7] Write a program to add 8-bit data at offset 0400H in 3000H segments to another 8-bit data available at 0500H offset in the same segment and store the result at 0700H in the same segment.

Ans :

         MOV  AX , 3000H        ; Move the data 3000H into AX register

           MOV DS , AX                ; The content of AX i.e. 3000H is move to DS 

 

The above two instruction establish the Data Segment and set segment address to 3000H.

 

         MOV AL , [0400H]      ; The 8-bit content of memory location having         

                                                    Address 3000H : 0400H are move to 8-bit AL    

                                                    Register

  ADD AL , [0500H]    ; The content of memory location having address                                                     3000H : 0500H are added with the content of  AL                                                     register and result is store in AL register 

            MOV [0700H] , AL     ;  the 8-bit content of AL register are moved to the                                                                                         memory location having address 3000H : 0700H


8] Assume that (AX) : ABCD16 and (BX) : 432116. What is the result of executing ADD  AX ,BX ?

Ans :

         Given, 

                      (AX)= ABCD16

                      (BX)= 432116

        Instruction : ADD AX, BX

The content of register AX and BX are added and the result is stored in the AX register 

(AX) = ABCD16 = 10101011110011012  

ADD

(BX) = 432116 = 01000011001000012

(AX) = DDDD16= 11101110111011102

Hence after executing the instruction the result stored in the AX is DDDD16.

9)  Two byte sized register are stored at the symbolic offset address NUM1 and NUM2 respectively. Write an instruction sequence to generate their sum and store it at NUM3. The SUM is to be formed by adding the values at NUM1 and that at NUM2. Assume that all storage location are in the current data segment. (6 M/7 M) 

Ans : 

          Let us assume that  the memory locations NUM1 ,NUM2 and NUM3 are in the same data segment 

MOV AX, @data                    ;  Establish data segment

MOV DS , AX                           

MOV AL, [NUM1]                  ;  Get the second BCD number

MOV AL, [NUM2]                  ;  Adding the values  

DAA                                          ;  Apply BCD adjustment 

MOV [NUM3] , AL                 ;   Save the result

10) Memory location 00490H through 00493H contain respectively 0A,9C, 82 and 78. What does AX contain after each instruction? (Assume that SI contains 0490H and BP contain 0002H)

i)        MOV Ax, [SI] 
ii)      MOV Ax, [SI +1] 
iii)     MOV Ax, [SI] [BP].  (6 M) 


Given ,  (SI) = 0490H

                     = 0490H x 10H

                     = 04900H                (BP)= 0002H i] MOV AX , [SI] 

In this instruction the content of memory location whose address is contain by SI is moved to the AX register. The content of memory location 00490H is 0AH and 00491H is 9CH .Hence, the content of 00490H and 00491H is moved to the register AX as AX is a 16-bit. After performing instruction the content of AX will be:

                                                         (AX)=(9C0A)16


ii]    MOV AX , [SI + 1] 

In this instruction the content of memory location whose address is contain by (SI + 1) is moved to the AX register. The memory address contain by (SI + 1) is 00491H .The content of memory location 00491H is 9CH and 00492H is B2H. Hence, the content of 00491H and 00492H is moved to the register AX. After performing instruction the content of AX will be:

                                                         (AX)=(B29C)16

 

iii]  MOV AX , [SI] [BP] 

In this instruction the content of memory location whose address is contain by (SI + BP) is moved to the AX register. The memory address contain by (SI + BP) is 00492H .The content of memory location 00492H is B2H and 00493H is 78H. Hence, the content of 00492H and 00493H is moved to the register AX. After performing instruction the content of AX will be:

                                                         (AX)=(78B2)16