Here is a program to read the status of a switch connected to P1.1 and control an LED connected to P1.2 based on the switch status:
MOV P1,#00h; Initialize port 1 pins as input and output
SETB P1.1; Set P1.1 as input
SETB P1.2; Set P1.2 as output
LOOP:
JNB P1.1,LED_OFF; If switch is open (0), jump to LED_OFF
SETB P1.2; If switch is closed (1), turn on LED
SJMP LOOP
LED_OFF:
CLR P1.2; If switch is
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Assembly program instructions
1.
2.
3.
4.
5.
6.
7.
8. An assembly language program statement consists of three fields: Labels, instructions and
comments. The arrangement of these three fields in a program is shown below.
1. label assigns a name to a memory location or program statement. It must be followed by the colon
symbol “:”. While using label as a part of an instruction, the colon symbol should not be used.
They are also used to define the symbols. The name of any register or an instruction of a
microcontroller cannot be used as a label.
2. Instruction
Each instruction has two parts; one is operation to be performed called as operation code (op-code). For
example, ADD,
MOV, INC, etc.
The second part is data on which operation is to be performed called as operands.
There are two types of operands:
1. Source operand(s): The operands that are input for an operation. The operation may involve one or two
operands.
2. Destination operand(s): These operands will store the result of an operation.
19. It should be noted that the access to memory locations between 80H to FFH that do not exist physically
will result into errors
Can we modify P (parity) bit by writing data directly in to PSW? What will be status of P flag after
execution of each of the following instructions?
MOV A, # 07H
MOV PSW, #00H
Copy the contents of the DPTR to internal RAM address 10H (DPL) and 11H (DPH)
20.
21.
22.
23.
24.
25.
26.
27. EXTERNAL MEMORY DATA MOVEMENTS
• The external memory in the 8051 based system may be either data memory (RAM) or program memory
(ROM).
• Instructions that access external memory always use indirect addressing mode.
• Two different set of instructions are used to transfer data to/from data memory and from program
memory.
• Data Memory Access
• The data memory can be as large as 64 Kbytes.
• Register R0, R1 and DPTR can be used as a pointer (indirect addressing) to access data bytes from
the external RAM.
• R0 and R1 have limitation to access only address range from 00H to FFH because they are 8-bit
register (using 8-bit, we can access 28 locations, i.e. 256 bytes – 00H to FFH).
• DPTR can address any location from 0000H to FFFFH (64 Kbytes, 216 locations).
• Again to remind, only R0 and R1 can be used with indirect addressing mode
• Mnemonic used for external data memory transfer is MOVX. The letter ‘X’ in the mnemonic indicates
the external data memory
28. DPTR or Ri register should be initialized with address of the desired data.
Note that all data transfer in this group occurs through Accumulator only, i.e. all external data
movements require the A register either as source or destination operand.
29.
30. Program
The word ‘HI’ is burned (written) in the flash ROM address 100H (‘H’) and 101H (‘I’). Copy this
word in to internal RAM address 10H and 11H.
32. PUSH AND POP INSTRUCTIONS
It is associated with stack operation. Using these instructions, the data is transferred between
stack and specified direct address.
The stack is a special memory area in the internal RAM that is used for temporary storage and
retrieval of the data, while the execution of a program.
It is Last In First Out (LIFO) type memory.
The data stored in the stack can be numbers or address. The stack is accessed with the help of
stack pointer (SP) register.
SP holds address (of internal RAM) where data from source operand will be saved (pushed) or
data to destination address will be retrieved (popped).
Stack pointer always points to top of the stack, i.e. last memory address accessed.
It should be initialized to a defined value (default value of SP is 07H).
33.
34. Copy the contents of registers R0 to R7 into internal RAM addresses 40H to
47H respectively using PUSH instructions
44. Represent –6 and –128 in 8–bit binary using 2’s complement representation.
45.
46.
47.
48. Multiply the contents of R0 and R1 and place the result into R2 (MSByte) and R3 (LSByte)
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73. Assume that a switch is connected to pin P1.1 and the LED is connected to pin P1.2. Write a program
to read the status of switch and send this status to LED.