You are on page 1of 9

SIDDARTHA INSTITUTE OF SCIENCE AND TECHNOLOGY :: PUTTUR

Siddharth Nagar, Narayanavanam Road – 517583


UNIT-IV

QUESTIONS AND ANSWERS

Subject Code : Microprocessors and Microcontrollers(19EC0421) Course & Branch:


B.Tech – ECE,EEE
Year & Sem: III-B.Tech & II - Sem Regulation:R19

Q1a) Describe the all the different addressing mode supported by 8051with suitable examples.

Addressing mode is a way to address an operand.

Five addressing modes for 8051. They are

1) Immediate addressing mode :Data is specified in instruction

MOV A,#04H

2)Register Addressing Mode:Data is present in register

MOV A, R4

3)Direct addressing mode :Data is present in memory ,its address is specified in an instruction

MOV A,30H

4.Register indirect addressing mode : Data is present in memory ,its address is specified in register

MOV R0,#30H

MOV A,@R0

5) Indexed addressing mode.: Data is present in memory its address is the combination of base and
index

MOVC A,@A+DPTR
1b) Explain the moving data instructions of 8051 microcontroller with an example.
MOV R2, 35H
It is an example of MOV Rn, a8. The content of location 35H of internal memory is moved to register R2.
MOV 0F0H, #12H
It is an example of type MOV a8, #d8. Here the12H will be stored at register B. The equivalent
instruction of this one is
MOV B, #25H
PUSH 0F0H
This is an example of PUSH a8. Here the contents of register B is pushed on the stack.
POP 40H
This is like POP a8. It indicates the content of stack top is moved to the internal RAM location 40H.
XCH A, R2
This is like XCH A, Rn. This instruction is used to exchange the content of A and register R2.
XCHD A @R0
This instruction is like the instruction XCHD A,@Ri. Using this instruction the LS digit of A and LS
digit of internal RAM location, which is pointed by R0 are swapped.
Q2a)Describe the DJNZ reg, label instruction with an example
MOV R3,#03H
up:

DJNZ R3,up
In djnz instruction it decrement content of R3 by 1 and check is it R3 is not equal to zero then jump to
label(up),once r3 become zero then it execute instruction below djnz.
Q2b)Explain the function of DAA and PUSH instruction with an example
The DAA instruction adjusts the eight-bit value in the Accumulator resulting from the earlier
addition of two variables (each in packed-BCD format),
producing two four-bit digits. Any ADD or ADDC instruction may have been used to perform the
addition.
The PUSH instruction increments the stack pointer and stores the value of the specified byte
operand at the internal RAM address indirectly referenced by the stack pointer.
Q3a)Describe how instruction MOVC A,@A+DPTR can be used in reading data from table.
MOVC moves a byte from Code(ROM) Memory into the Accumulator.
Here, the address for the operand is the sum of contents of DPTR and Accumulator.
b) Discuss the logical operations Instructions of 8051 microcontroller with an example.
ANL A, #14 H:
This is AND instruction performed between the data of register A, and the 14H.

ORL A, #14H
ORL A, R0
ORL A, 14H
ORL A, @R0

XRL A, #14H
XRL A, R0
XRL A, 14H
XRL A, @R0
Q4a)List various arithmetic operations performed in 8051 microcontroller

Addition:
ADD A,Rn
ADD A,Direct
ADD A,@Ri
ADD A,#data

ADDC A,Rn
ADDC A,Direct
ADDC A,@Ri
ADDC A,#data
Subtraction:
SUBB A,Rn
SUBB A,Direct
SUBB A,@Ri
SUBB A,#data
Increment:
INC A
INC Rn
INC Direct
INC @Ri
Decrement:
DEC A
DEC Rn
DEC Direct
DEC @Ri
Multiplication:
MUL AB
Division:
DIV AB
Decimal Adjust After Addition:
DAA
Q4 b)Explain any three arithmetic opeartions Instructions of 8051 microcontroller with an example.
Any three with example
ADD A,Rn
Example: ADD A,R1
INC Rn
Example: INC R2
MUL AB
Example: MOV A,#4
MOV B,#5
MUL AB
Q5a)Discuss the following instructions of 8051 microcontroller with an example.

(i) Bit level (ii) Byte level


Ans: (i) Bit level
CLR C
CLR CThis instruction is used to clear the carry flag to 0.

CLR bit
SETB C
SETB bit
SETB 0D5HThis instruction of type SETB bit. It sets to 1bit. Here the bit is D5 (which is the F0 pin of PSW). This instruction can also be written like this SETB
PSW.5 or SETB F0.

CPL C
CPL C It complements the content of Carry Flag

CPL bit
ANL C, bit
ANL C, 07Using this instruction, it ANDs the C-bit with bit 7. (Here 7 indicates the MS bit in internal RAM location20H.)

ORL C, /bit
ORL C, /07This instruction ORs the C-bit with the complement of bit 7.
MOV C, 05This instruction will move the content of bit 5to carry.

MOV C, bit
MOV C, 05This instruction will move the content of bit 5to carry.

JC rel
JC LABELThis is a jump instruction. When the Carry flag is 1, it will jump to the LABEL.

(ii) Byte level


MOV R2, 35H
It is an example of MOV Rn, a8. The content of location 35H of internal memory is moved to register R2.
MOV 0F0H, #12H
It is an example of type MOV a8, #d8. Here the12H will be stored at register B. The equivalent
instruction of this one is
MOV B, #25H
ADD A,Rn
Example: ADD A,R1
Q5b)How the stack can be used in subroutine uses of stack in 8051 microcontroller.
The stack is a LIFO (last in, first out) data structure implemented in the RAM area and is used to store
addresses and data when the microprocessor branches to a subroutine. Then the return address used to
get pushed on this stack. Also to swap values of two registers and register pairs we use the stack as well.
As each subroutine is called the machine saves the return address of the calling program on a stack.
This ensures that subroutine returns are processed in the reverse order of subroutine calls, which is the
desired operation.
Q6a)Differentiate between Jump and Call instructions.
JUMP Instruction CALL instruction

By using JUMP, the program control By using CALL instruction, the program
transfers to a location which is also a part control transfers to a location which is not a
of the main program part of main program.

Here the addressing mode is Immediate Here the addressing mode is Immediate and
Register Indirect.

We do not need to initialize the Stack We have to initialize the Stack Pointer (SP)
Pointer (SP) to perform the JUMP before using some CALL instruction.
instruction.

The program counter value is not Pushed The value of program counter is pushed into
into Stack stack before going to the pointed location.

No return instruction is needed after After CALL, it enters into a subroutine, to


JUMP instruction. come back from subroutine we need return
instruction.

The value of stack pointer remain The value of Stack Pointer is decremented
unchanged by 2.

10 T-States are required to perform JUMP 18 T-States are required to perform CALL
instruction instruction.

3 Machine cycles are needed for JUMP 5 Machine cycles are needed for CALL.

Q6b) ) Explain Jump and Call instructions of 8051 microcontroller with an example.
Unconditional Jump Instructions
There are two unconditional jumps in 8051 −
 LJMP (long jump) − LJMP is 3-byte instruction in which the first byte represents opcode, and the
second and third bytes represent the 16-bit address of the target location. The 2-byte target address
is to allow a jump to any memory location from 0000 to FFFFH.
 SJMP (short jump) − It is a 2-byte instruction where the first byte is the opcode and the second
byte is the relative address of the target location. The relative address ranges from 00H to FFH
which is divided into forward and backward jumps; that is, within –128 to +127 bytes of memory
relative to the address of the current PC (program counter). In case of forward jump, the target
address can be within a space of 127 bytes from the current PC. In case of backward jump, the
target address can be within –128 bytes from the current PC.
The following table lists the conditional jumps used in 8051 –
JZ Jump if A = 0
JNZ Jump if A ≠ 0
DJNZ Decrement and Jump if register ≠ 0
CJNE A, data Jump if A ≠ data
CJNE reg, #data Jump if byte ≠ data
JC Jump if CY = 1
JNC Jump if CY ≠ 1
JB Jump if bit = 1
JNB Jump if bit = 0
JBC Jump if bit = 1 and clear bit
 JZ (jump if A = 0) − In this instruction, the content of the accumulator is checked. If it is zero, then
the 8051 jumps to the target address. JZ instruction can be used only for the accumulator, it does
not apply to any other register.
 JNZ (jump if A is not equal to 0) − In this instruction, the content of the accumulator is checked
to be non-zero. If it is not zero, then the 8051 jumps to the target address.
 JNC (Jump if no carry, jumps if CY = 0) − The Carry flag bit in the flag (or PSW) register is
used to make the decision whether to jump or not "JNC label". The CPU looks at the carry flag to
see if it is raised (CY = 1). If it is not raised, then the CPU starts to fetch and execute instructions
from the address of the label. If CY = 1, it will not jump but will execute the next instruction below
JNC.
 JC (Jump if carry, jumps if CY = 1) − If CY = 1, it jumps to the target address.
 JB (jump if bit is high)
 JNB (jump if bit is low)
CALL Instructions
CALL is used to call a subroutine or method. Subroutines are used to perform operations or tasks that
need to be performed frequently. This makes a program more structured and saves memory space.
There are two instructions − LCALL and ACALL.
LCALL (Long Call):LCALL is a 3-byte instruction where the first byte represents the opcode and the
second and third bytes are used to provide the address of the target subroutine. LCALL can be used to call
subroutines which are available within the 64K-byte address space of the 8051.
To make a successful return to the point after execution of the called subroutine, the CPU saves the
address of the instruction immediately below the LCALL on the stack. Thus, when a subroutine is
called, the control is transferred to that subroutine, and the processor saves the PC (program counter) on
the stack and begins to fetch instructions from the new location. The instruction RET (return) transfers
the control back to the caller after finishing execution of the subroutine. Every subroutine uses RET as
the last instruction.
ACALL (Absolute Call):ACALL
is a 2-byte instruction, in contrast to LCALL which is 3 bytes. The target
address of the subroutine must be within 2K bytes because only 11 bits of the 2 bytes are used for
address. The difference between the ACALL and LCALL is that the target address for LCALL can be
anywhere within the 64K-bytes address space of the 8051, while the target address of CALL is
within a 2K-byte range.
Q7a)Develop and Write an assembly program of 8051 microcontroller to multiply two 8-bit numbers
and store the result in a memory location with help of algorithm and flowchart.

ORG 0000H
MOV R1,#30H
MOV A,@R1
INC R1
MOV B,@R1
MUL AB
INC R1
MOV @R1,A
INC R1
MOV @R1,B
END
Q7b)Compare CALL and PUSH instructions
CALL PUSH

After the execution of CALL PUSH instructions is used to save the


instructions, the μP automatically contents of specified registers on the
stores the return address of 16 bit stack.
into stack.

After the execution of CALL In this case after PUSH operation,


instructions, the contents of stack contents of stack pointer are also
pointer register incremented. incremented.

Q8a)Explain how the 8051 microcontroller performs rotate and swap operations with an example.

SWAP A: Interchange the nibbles of register A; put the high nibble in the low nibble position and the
low nibble in the high nibble position
8b)Describe the operation of return instruction in 8051 microcontroller with suitable example.
Ans:Description. The ret instruction transfers control to the return address located on the stack.
This address is usually placed on the stack by a call instruction. Issue the ret instruction within the
called procedure to resume execution flow at the instruction following the call .

Q9a) Develop and write an assembly program of 8051 microcontroller to divide two 8-bit numbers and
store the result in a memory location.
ORG 0000H
MOV R1,#30H
MOV A,@R1
INC R1
MOV B,@R1
DIV AB
INC R1
MOV @R1,A
INC R1
MOV @R1,B
END
Q9b) Develop an assembly program of 8051 microcontroller to subtract two 8-bit numbers and store the
result in a memory location.
ORG 0000H
MOV R1,#30H
MOV A,@R1
INC R1
MOV B,@R1
SUBB A,B
INC R1
MOV @R1,A
INC R1
MOV @R1,B
END
10a)Develop and Write an assembly program of 8051 microcontroller to logically AND two 8-bit
numbers and store the result in a memory location.
ORG 0000H
MOV R1,#30H
MOV A,@R1
INC R1
MOV B,@R1
ANL A,B
INC R1
MOV @R1,A
INC R1
MOV @R1,B
END
b) Develop and Write an assembly program of 8051 microcontroller to find largest number among
given 10 numbers and store the result in a memory location.
ORG 0000H
MOV R2,#0AH
MOV R1,#30H
MOV A,@R1
up:INC R1
MOV B,@R1
CJNE A,B,Next
Next:JNC down
MOV A,B
down:INC R1
DJNZ R2,up
MOV @R1,A
END

You might also like