[go: up one dir, main page]

0% found this document useful (0 votes)
23 views8 pages

Module2 Solutions

The document provides a comprehensive question bank with solutions related to the 8051 microcontroller, covering various topics such as arithmetic operations, bit manipulation, instruction explanations, and addressing modes. It includes practical examples for tasks like calculating averages, converting data formats, and using subroutines. Additionally, it highlights the benefits of subroutines and error checking in instructions.

Uploaded by

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

Module2 Solutions

The document provides a comprehensive question bank with solutions related to the 8051 microcontroller, covering various topics such as arithmetic operations, bit manipulation, instruction explanations, and addressing modes. It includes practical examples for tasks like calculating averages, converting data formats, and using subroutines. Additionally, it highlights the benefits of subroutines and error checking in instructions.

Uploaded by

sgchandan2003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Module 2 Question Bank Solutions –

8051 Microcontroller

Module 2 Question Bank Solutions – 8051 Microcontroller

---

1) Add two 16-bit numbers in R1R0 and R3R2, result in R6 R5 R4:


MOV A, R0
ADD A, R2
MOV R4, A
MOV A, R1
ADDC A, R3
MOV R5, A
CLR A
ADDC A, #00H
MOV R6, A

2) Bit Manipulation Instructions:


- `SETB bit` – Set a bit to 1

- `CLR bit` – Clear a bit to 0

- `CPL bit` – Complement a bit

- `MOV C, bit` – Move bit to Carry

- `MOV bit, C` – Move Carry to bit

- `ANL C, bit` – AND bit with Carry

- `ORL C, bit` – OR bit with Carry


3) Instruction Explanation:
- `JMP @A+DPTR` – Jump to (A + DPTR), used for lookup tables

- `XCHD A, @Ri` – Exchange lower nibble of A with @Ri

- `JBC bit, rel8` – Jump if bit set, then clear bit

- `MOVC A, @A+PC` – Move code byte at (PC + A) to A

4) Multiply 16-bit by 8-bit:


MOV A, R0
MOV B, R2
MUL AB
MOV R4, A
MOV R5, B
MOV A, R1
MOV B, R2
MUL AB
ADD A, R5
MOV R5, A
MOV R6, B

5) PUSH & POP Example:


MOV SP, #60H
MOV A, #55H
PUSH ACC
MOV A, #00H
POP ACC

6) Conditional Logic Based on X:


MOV A, 20H
CJNE A, #00H, CHECK1
MOV A, 21H
ANL A, 22H
SJMP STORE
CHECK1:
CJNE A, #01H, CHECK2
MOV A, 21H
ORL A, 22H
SJMP STORE
CHECK2:
CJNE A, #02H, ELSE
MOV A, 21H
XRL A, 22H
SJMP STORE
ELSE:
CLR A
STORE:
MOV 23H, A

7) Factorial using subroutine:


MOV R0, #05H
MOV R1, #01H
CALL FACT
HERE: SJMP HERE
FACT:
MOV A, R0
CJNE A, #01H, NEXT
RET
NEXT:
MOV A, R0
DEC R0
MOV B, R1
MUL AB
MOV R1, A
SJMP FACT

8) Average of 10 marks (ext RAM @8000H):


MOV DPTR, #8000H
MOV R0, #0AH
CLR A
CLR B
LOOP:
MOVX A, @DPTR
ADD A, B
MOV B, A
INC DPTR
DJNZ R0, LOOP
MOV A, B
MOV R1, #0AH
DIV AB
MOV 30H, A

9) Addressing Modes of 8051:


- Immediate: `MOV A, #25H`

- Register: `MOV A, R1`

- Direct: `MOV A, 30H`

- Indirect: `MOV A, @R0`

- Indexed: `MOVC A, @A+DPTR`

10) Instruction Error Check:


- CJNE @RI, #D_ADDRESS, REL8 ❌ → `CJNE @R0, #data, rel`

- ADDC @RI, A ❌ → `ADDC A, @R0`

- DJNZ #DATA, REL8 ❌ → `MOV Rn, #data` then `DJNZ Rn, rel`

- MOVX @DPTR, R1 ❌ → `MOVX @DPTR, A`

11) Packed BCD to ASCII (e.g., 25H):


MOV A, #25H
ANL A, #0FH
ORL A, #30H
MOV R6, A
MOV A, #25H
SWAP A
ANL A, #0FH
ORL A, #30H
MOV R5, A

12) Binary to Packed BCD (value at 40H):


MOV A, 40H
MOV B, #0AH
DIV AB
MOV R2, A
SWAP A
ANL A, #F0H
ORL A, B
MOV 50H, A
CLR A
MOV 51H, A

13) Stack Role in Subroutines:


- Stack stores return address during `CALL`

- `RET` retrieves it

- Allows return to main program

14) Multiply 25 by 10 using addition:


MOV A, #00H
MOV R0, #0AH
MOV R1, #19H
LOOP:
ADD A, R1
DJNZ R0, LOOP

15) Transfer A, R0, R1 of Bank0 to B, R0, R1 of Bank1 using stack:


PUSH ACC
PUSH R0
PUSH R1
MOV PSW, #08H
POP R1
POP R0
POP B

16) Realize Y = A*B + C (A:30H, B:40H, C:50H):


MOV C, 30H
JNC A0
MOV A, 40H
JZ A0
SETB C
A0:
MOV A, 50H
JZ A1
ORL C, #01H
A1: NOP

17) Jump & Call Address Ranges:


- LJMP/LCALL: 16-bit, full 64KB

- AJMP/ACALL: 11-bit, within 2KB page

- SJMP: 8-bit signed, −128 to +127

18) MUL & DIV Instructions:


MOV A, #05H
MOV B, #04H
MUL AB ; A = 14H, B = 00H
MOV A, #09H
MOV B, #02H
DIV AB ; A = 04H, B = 01H
19) Find smallest of 20 numbers from 60H to 73H:
MOV R0, #60H
MOV A, @R0
INC R0
MOV R1, #13H
NEXT:
MOV B, @R0
CJNE A, B, CHECK
SJMP CONT
CHECK:
JC CONT
MOV A, B
CONT:
INC R0
DJNZ R1, NEXT
MOV 90H, A

20) SUBB instruction with/without borrow:


MOV A, #05H
CLR C
SUBB A, #02H ; A = 03H
MOV A, #05H
SETB C
SUBB A, #02H ; A = 02H

21) Status of CY, AC, P for MOV A, #9CH + ADD A, #64H:


- CY = 1 (overflow)

- AC = 1 (lower nibble overflow)

- P = 1 (result 00H = even parity)

22) Copy 55H into 40H:


(i) Direct:

MOV 40H, #55H


(ii) Register indirect:

MOV R0, #40H


MOV @R0, #55H

23) Benefits of Subroutines:


- Code reuse

- Modularity

- Saves memory

- Easier to debug

- Better readability

You might also like