Mces03 8051alp PDF
Mces03 8051alp PDF
Mces03 8051alp PDF
1
Module-2 : The 8051 ALP
8051 ALP; Programming model, Instruction set, Addressing modes; 8051
programming in C.
Book:
1. The 8051 Microcontroller and Embedded Systems Using Assembly and C, Mazidi M. A..
2. Microcontrollers Principles and Applications, Ajit Pal
Figures have been taken from Lectures slides on Microcontrollers prepared by
Chung-Ping Young, Home Automation, Networking, and Entertainment Lab
Dept. of Computer Science and Information Engineering
National Cheng Kung University, TAIWAN
2
Data Representation
Sign-magnitude
+25= 0 0011001
-25= 1 0011001
Ones complement
+25= 0 0011001
-25= 1 1100110
Twos complement
+25= 0 0011001
-25= 1 1100111
Sign extension
+25= 00011001 0000000000011001
-25= 11100111 1111111111100111 3
8051 Instructions
1-byte Instruction: CPL, RLC, SWAP, ADD
2-byte Instruction:
OpCode Immediate or I/O addr.
ADD A, #DATA
3-byte Instruction
OpCode addr., addr.
MOV mem_addr.1, mem_addr. 2
4
8051 RAM Locations
128 bytes:
Locations 00H-1FH: Register banks and
stack
20H-2FH: Bit addressable portion
30H-7FH: As RAM locations
5
Addressing Modes
Inherent: CPL, RLC, RRC
Immediate: MOV A, #26H; MOV DPTR, #4521H
MOV P1, #55H
Register: MOV A, R7; MOV R0, A
Direct: MOV A, 56H; MOV 7FH, R4// The address
generally in the range 30H-7FH.
Register Indirect: Internal RAM: MOV A, @Ri , i=0,1, SP;
External RAM: MOVX A, @R1; MOVX @DPTR, A
Indexed (Based): MOVC A, @A+DPTR, MOVC A, @A+PC
// C-code
Relative: SJMP rel ; PC=PC+2+rel // rel-a signed 8-bit offset
Stack: PUSH 0E0H, POP 04H //not PUSH A, POP R4
6
Instruction Set
Data transfer: General purpose, ACC-specific, Addr.-obj
Arithmetic: ADD, ADDC, MUL AB, DIV AB
Logic: CLR A, CLR A.7, SETB C, RL
Control Transfer: ACALL (abs. call), LCALL, RET,
AJMP (abs. jump), LJMP, SJMP
JMP @a+DPTR; PC=A+DPTR
JZ, JNZ, CJNE, DJNZ
RET, RETI
Bit manipulation Instructions: SETD bit, CLR bit
7
Instructions affecting the flag bits
8
PSW Register
Carry
9
Pseudo codes
ORG Origin
EQU Equate
DB Define byte: How is it different from
EQU?
END End of source program
10
Example
11
Example
12
Example
13
Delay Generation
Clock Frequency=11.0592 MHz
Time for 1 machine cycle=12*10-6/11.0592 s
= 1.085 s.
2230 // 1 m/c
// 2 m/c
15
Problem
6. Searching
7. Sorting
16
Typical Steps in Coding
17