---
title: "Get data from P0, send to P1 (asm and C)"
subject: "Embedded System"
chapter: 9
key: "semester_6/embedded_system:8051-p0-to-p1-assembly-c"
source: https://www.bctengineer.com/q/semester_6/embedded_system/8051-p0-to-p1-assembly-c
site: BCT Engineering
---

# Get data from P0, send to P1 (asm and C)

Embedded System · Chapter 9: Microcontrollers in Embedded Systems

- Asked in: 2069 Bhadra, 5 marks
- Video: [How to write C Program to send values on 8051 Ports? | Part 4 | 8051 Programming in C](https://www.youtube.com/watch?v=X7D4CU_oyYU) — Technogineer
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/embedded_system/8051-p0-to-p1-assembly-c
- Whole chapter: https://www.bctengineer.com/md/semester_6/embedded_system/chapter-9

## Question

Write an assembly program to get data from P0 and send it to P1 and compare with corresponding C program.

## 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.

## Answer

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

```asm
        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

```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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Why does the program start with MOV P0,#0FFH?
   A. To clear Port 0
   B. To write 1s so Port 0 can be used as an input
   C. To copy P1 to P0
   D. To enable interrupts
   Answer: B. Writing 1s to the port latches configures the pins as inputs. (Key point: Port as input)

2. How does the assembly loop move data from P0 to P1?
   A. MOV A,P0 then MOV P1,A inside a repeating loop
   B. MOV P1,P0 once
   C. MOVC A,@A+DPTR then MOVX
   D. DJNZ P0,P1
   Answer: A. The data is read from P0 into A, written to P1, and SJMP repeats it forever. (Key point: Data transfer steps)

3. Which is true when comparing the assembly and C versions?
   A. C is faster and smaller than assembly
   B. Assembly is portable to any controller
   C. Assembly gives full control and the smallest code; C is more readable and portable
   D. C needs more development time
   Answer: C. Assembly is smallest and fastest but hard to read and 8051-only; C is readable, portable and quicker to develop. (Key point: Assembly vs C)

4. Why may external pull-ups be needed on Port 0?
   A. P0 has no internal pull-ups, so open-drain sources need them
   B. P0 is output only
   C. P1 cannot drive LEDs
   D. The crystal needs them
   Answer: A. Port 0 has no internal pull-ups, so an open-drain source requires external pull-ups. (Key point: Port 0 pull-ups)

## Related in Embedded System

- [1 kHz square wave on P1.5 using timer](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-square-wave-timer) — Embedded System, chapter 9
- [Count number of 1s in ROM data](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-count-ones-asm) — Embedded System, chapter 9, asked 2×
- [Count number of 0s in ROM data](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-count-zeros-asm) — Embedded System, chapter 9, asked 2×
- [C program: sum of two 8-bit BCD numbers](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-bcd-sum-c) — Embedded System, chapter 9
- [Read switches at port 1, show on port 2](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-switch-port1-led-port2) — Embedded System, chapter 9, asked 2×

## Related in other subjects

- [8085 ALP: compare two tables of 16-bit data](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-compare-tables-1ffffh) — Microprocessor, chapter 2
- [Rules of inference: e-mail and program](https://www.bctengineer.com/question.md?key=semester_4%2Fdiscrete_structure%3Arules-inference-email-program) — Discrete Structure, chapter 1
- [Convert Hermite data to Bezier cubic](https://www.bctengineer.com/question.md?key=semester_4%2Fcomputer_aided_design%3Ahermite-to-bezier-conversion) — Computer Aided Design, chapter 3
- [8085 ALP: transfer data with more than 3 ones](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-ones-greater-than-3) — Microprocessor, chapter 2
