Programming Model of 8051 : E1 Chap 2 : IMP Q&A - BCS Guruji

Ad

Monday, November 21, 2022

Programming Model of 8051 : E1 Chap 2 : IMP Q&A

Q1. Explain different addressing modes of 8051 with suitable example.

Answer: Different addressing modes are as follows:

1. Immediate addressing: Here the instruction itself has data to be operated on or stored.

Example: MOV A, #20H 

This instruction loads value 20H in accumulator.

2. Direct addressing: Here the address of memory is directly given in instruction itself.

Example: MOV A, 30H 
This instruction will read data from memory with address 30H and store it in accumulator.

3. Indirect addressing: Here the register name is given which has address of required memory location.

Example: MOV A,@R0
This instruction copies data from memory location whose address is given in register R0 into accumulator.

4. Register Addressing: Here the operands are in register itself.

Example: MOV A,R0 
This instruction copies data from register R0 into accumulator.

5. External Indirect : It is used to access external memory.
It is of two types : 

Type 1: Data Memory Access : Here the pointer to data pointer or any register is given which contains address of memory location of data.

Example: MOVX A,@DPTR
This instruction copies data from external memory location into accumulator.

Type 2: Code Memory Access : 

Example : MOVC A,@A+DPTR
This instruction copies data from external program memory location whose address is given by sum of accumulator and data pointer into accumulator.


Q2. Explain the term assembler directives.

Answer: Assembler directives are statements that direct the assembler to do something. These are not instructions as they are effective only during assembly of a program.

Following are widely used assembly directives:

1. ORG- Originate: It allows us to set the beginning address to start the program.
Example : ORG 00 H; This starts program at location 0.

2. Define Byte (DB): It is used to declare byte type variable.
Example: DAT1 DB 24 ; Here DAT1 is variable name, DB is directive, 24 is decimal value initialized.

3. EQU (Equate): It is used to give name to some symbol or value in program.
Example: FACT EQU 04H ; Whenever FACT appears in instruction or another directive, the assembler substitues value 4.

4. END : It is placed at end of the source as it terminates the program.
Example: END;

5. Public and Extern: Public declares the variables defined in specific file.
Extern declares the variables that are used in present source file but defined in other source file.

Q3. Give operations of Instructions.
Answer: There are following types of instructions:
1. Data transfer instructions:
- MOV :
example : MOV A,@Ri : Move indirect RAM to accumulator.
MOV Rn,A : Move accumulator to register.

-MOVX : 
example : MOVX A, @DPTR : Move external ram to A.
MOVX @Ri, A : Move accumulator to external RAM. 

-MOVC :
example : MOVC A, @A+PC : Move code bye relative to PC to A.

-PUSH AND POP :
example : PUSH direct : Push direct byte onto stack.
POP direct : Pop direct byte from stack.

-XCH :
example: XCH A,Rn : Exchange register with accumulator

2. Arithmetic instructions : 
- INC:
example : INC A : It adds 1 to the accumulator.
- DEC:
example : DEC A : It subtracts 1 from accumulator.
- ADD:
example: ADD A,Rn : Add register to A.
-SUBB: 
example: SUBB A,Rn : Subtract register from A with borrow.
-MUL:
example: MUL AB: Multiplies A by B.
- DIV:
Example : DIV AB : Divides A by B.

3. Logical instructions : 
-ANL:
example: ANL A,Rn : AND register to the accumulator.
-ORL:
example: ORL A, Rn : OR register to the accumulator.
-XRL: 
example: XRL A,Rn: Exclusive -OR register to accumulator.
- CLR:
example: CLR A : Clear accumulator.
- CPL:
example: CPL A: Complement accumulator.

4. Rotate instructions:
- RL:
example: RL A : Rotate accumulator left
- RLC:
example: RLC A : Rotate accumulator left through carry.
- RR:
example : RR A : Rotate the accumulator to right.
- RRC:
example: RRC A: Rotate accumulator to right through carry.
- SWAP:
example: SWAP A: Swapn nibble within the accumulator.


Q4. Write a C program for LED blinking using 'C language'.
Answer:
#include<reg51.h>
sbit pin=P1^0;
void delay(int value)
{
int i,j;
for(i=0;i<=value;i++);
for(j=0;j<=5;j++);
}
void main()
{
while(1)
{
P1=0x01;
delay(500);
P1=0x00;
pin=0;
delay(500);
}
}


No comments:

Post a Comment