Part II The 8051 Assembly Language Stack Bit
Part II The 8051 Assembly Language Stack, Bit Addressing, Arithmetic EE/CS-352: Embedded Microcontroller Systems
A and B Registers • A and B can be accessed by direct mode as special function registers: • B – address 0 F 0 h • A – address 0 E 0 h - use “ACC” for direct mode EE/CS-352: Embedded Microcontroller Systems
Address Modes Stack-oriented data transfer – another form of register indirect addressing, but using SP mov sp, #0 x 40 push 0 x 55 pop 0 x 0 F 0 Note: can only specify RAM or SFRs in direct mode to push or pop. Therefore, to push/pop the accumulator cannot use a: push 0 E 0 h push a EE/CS-352: Embedded Microcontroller Systems
Stacks push pop stack pointer stack EE/CS-352: Embedded Microcontroller Systems
Address Modes Exchange Instructions – two way data transfer XCH a, 0 x 30 XCH a, R 0 XCH a, @R 0 XCHD a, @R 0 a[7. . 4] a[3. . 0] ; ; a M[30] a R 0 a M[R 0] exchange “digit” R 0[7. . 4] R 0[3. . 0] Only 4 bits exchanged EE/CS-352: Embedded Microcontroller Systems
Bit-Oriented Data Transfer • SFRs with addresses ending in 0 or 8 are bit-addressable. (80, 88, 90, 98, etc) • Carry flag (C) (bit 7 in the PSW) is used as a single-bit accumulator • RAM bits in addresses 20 -2 F are bit addressable EE/CS-352: Embedded Microcontroller Systems
Bit Addressable Memory 2 F 7 F 78 2 E 2 D 20 h – 2 Fh (16 locations X 8 -bits = 128 bits) 2 C 2 B 2 A 29 28 27 26 25 24 23 1 A 22 10 21 0 F 20 07 08 06 05 04 03 02 01 00 EE/CS-352: Embedded Microcontroller Systems
SFRs that are Bit Addressable Address SFRs with addresses of multiples of 0 and 8 are bit addressable. SFRs Pink are implemented in enhanced C 8051 F 020 Register 0 x. F 8 SPI 0 CN 0 x. F 0 B 0 x. E 8 ADC 0 CN 0 x. E 0 ACC 0 x. D 8 PCA 0 CN 0 x. D 0 PSW 0 x. C 8 T 2 CON 0 x. C 0 SMB 0 CN 0 x. B 8 IP 0 x. B 0 P 3 0 x. A 8 IE 0 x. A 0 P 2 0 x 98 SCON 0 x 90 P 1 0 x 88 TCON 0 x 80 P 0 EE/CS-352: Embedded Microcontroller Systems
Data Processing Instructions Arithmetic Instructions Logic Instructions EE/CS-352: Embedded Microcontroller Systems
Arithmetic Instructions • • Add Subtract Increment Decrement Multiply Divide Decimal adjust EE/CS-352: Embedded Microcontroller Systems
Arithmetic Instructions Mnemonic Description ADD A, byte add A to byte, put result in A ADDC A, byte add with carry SUBB A, byte subtract with borrow INC A increment A INC byte increment byte in memory INC DPTR increment data pointer DEC A decrement accumulator DEC byte decrement byte MUL AB multiply accumulator by b register DIV AB divide accumulator by b register DA A decimal adjust the accumulator EE/CS-352: Embedded Microcontroller Systems
ADD Instructions These instructions affect 3 bits in PSW: C = 1 if result of add is greater than FF AC = 1 if there is a carry out of bit 3 OV = 1 if there is a carry out of bit 7, but not from bit 6, or visa versa EE/CS-352: Embedded Microcontroller Systems
Instructions that Affect PSW bits EE/CS-352: Embedded Microcontroller Systems
ADD Examples mov a, #0 x 3 F add a, #0 x. D 3 • What is the value of the C, AC, OV flags after the second instruction is executed? EE/CS-352: Embedded Microcontroller Systems
Signed Addition and Overflow 2’s 0000 … 0111 1000 … 1111 complement: 0000 00 0 1111 0000 7 F 127 80 -128 1111 FF -1 EE/CS-352: Embedded Microcontroller Systems
- Slides: 15