- 2069 Bhadra · 5 marks
Get data from P0, send to P1 (asm and C)
Short answer
Configure Port 0 as input by writing all ones; then continuously read its value and write to Port 1. Assembly: MOV P0,#0FFH; MOV A,P0; MOV P1,A; SJMP. Equivalent C: P0=0xFF; while(1) P1=P0;. External pull-up resistors are needed on Port 0.
Write an assembly program to get data from P0 and send it to P1 and compare with corresponding C program.
Port 0 is made an input by writing 1s to it; then its value is repeatedly read into A and written to Port 1.
Assembly
ORG 0000H
MOV P0,#0FFH ; configure Port 0 as input
BACK: MOV A,P0 ; read the data at P0 into A
MOV P1,A ; send it to P1
SJMP BACK ; repeat forever
END
Equivalent C
#include <reg51.h>
void main(void)
{
P0 = 0xFF; /* Port 0 as input */
while (1)
P1 = P0; /* read P0, write to P1 */
}
Comparison
| Point | Assembly | C |
|---|---|---|
| Length | 4 instructions | 1 statement in the loop |
| Control | Full control of registers and timing | Compiler chooses registers |
| Readability | Low | High |
| Portability | Only 8051 | Easily ported to other controllers |
| Speed, code size | Smallest and fastest | Slightly larger, but acceptable |
| Development time | Longer | Shorter |
Both programs behave the same. Port 0 has no internal pull-ups (its pins are open-drain), so external pull-up resistors (about 10 kΩ) are normally added on P0 when it reads switches or open-drain outputs.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- 1 kHz square wave on P1.5 using timer · Embedded System, chapter 9
- Count number of 1s in ROM data · Embedded System, chapter 9 · asked 2×
- Count number of 0s in ROM data · Embedded System, chapter 9 · asked 2×
- C program: sum of two 8-bit BCD numbers · Embedded System, chapter 9
- Read switches at port 1, show on port 2 · Embedded System, chapter 9 · asked 2×
- 8085 ALP: compare two tables of 16-bit data · Microprocessor, chapter 2
- Rules of inference: e-mail and program · Discrete Structure, chapter 1
- Convert Hermite data to Bezier cubic · Computer Aided Design, chapter 3
- 8085 ALP: transfer data with more than 3 ones · Microprocessor, chapter 2