Instr Set Of 8051

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Instr Set Of 8051 as PDF for free.

More details

  • Words: 1,535
  • Pages: 23
8051 Microcontroller – Architecture, Intro to Assembly Programming EE4380 Fall 2002 Class 2

Pari vallal Kannan Center for Integrated Circuits and Systems University of Texas at Dallas

Class –2: Objective l l l l l l

8051 internal architecture Register Set Instruction Set Memory Map Intro to Stack, SFRs Assembly language programming

21-Jan-03

2

8051 Architecture l

Programmer’s View – – –

l

Register Set Instruction Set Memory map

Hardware Designer’s View – – –

Pinout Timing characteristics Current / Voltage requirements

21-Jan-03

3

Programmer’s View – Register Set l

Registers – – – – – – –

A, B, R0 to R7 : 8 bit registers DPTR : [DPH:DPL] 16 bit register PC : Program Counter (Instruction Ptr) 16bits 4 sets of register bank R0-R7 Stack pointer SP PSW : Program Status Word (a.k.a Flags) SFR : Special Function Registers l

21-Jan-03

Control the on-board peripherals

4

Assembly – Absolute Basics l

Intel Assembly format Operation destination source

l

Values are to be preceded by a # sign –

l

#55, #32 etc

Hex values are to be followed by H –

l

; comment

#55H, #32H

If the first figure in a hex quantity is a letter (AF) then a 0 must precede it –

#0FFH, #0C1H, #0D2H

21-Jan-03

5

Register Set – Accumulator A, ACC l l

Commonly used for moving data around, logic and arithmetic operations on 8bit data Examples mov A, R0 push ACC mov A, #10 mov B, A mov A, 10 mov A, 0xFF mov A, 0FFH

21-Jan-03

;copy contents of R0 to A ;store A onto stack ;A ß 10 ;B ß A ;A ß mem(10) ;A ß 0xFF ;same as above

6

Register Set – B Register l l

Commonly used as a temporary register, much like a 9th R register Used by two opcodes –

l

mul AB, div AB

B register holds the second operand and will hold part of the result – –

Upper 8bits of the multiplication result Remainder in case of division

21-Jan-03

7

Register Set – R0 to R7 l l l l l l

Set of 8 registers R0, R1, … R7, each 8 bit wide Widely used as temporary registers Available in 4 banks (effectively 4x8 registers) Bank is chosen by setting RS1:RS0 bits in PSW Default bank (at power up) is the bank0 Examples mov R0, A mov A, R0 mov R1, #45

21-Jan-03

;R0 ß A ;A ß R0 ;R1 ß 45

8

Registers - DPTR l l l

l

16 bit register, called Data Pointer Used by commands that access external memory Also used for storing 16bit values mov DPTR, #data16

; setup DPTR with 16bit ext address

movx A, @DPTR

; copy mem[DPTR] to A

DPTR is useful for string operations, look up table (LUT) operations

21-Jan-03

9

Registers - PC l l l l

PC is the program counter Referred to as the Instruction Pointer (IP) in other microprocessors PC points to the next program instruction always After fetching an instruction (1 or multi byte), PC is automatically incremented to point to the next instruction

21-Jan-03

10

Registers - SP l l

SP is the stack pointer SP points to the last used location of the stack – –

l l l l

push will first increment SP and then copy data pop will first copy data and then decrement SP

In 8051, stack grows upwards (from low mem to high mem) and can be in the internal RAM only On power-up, SP is at 07H Register banks 2,3,4 (08H to 1FH) is the default stack area Stack can be relocated by setting SP to the upper memory area in 30H to 7FH –

mov SP, #32H

21-Jan-03

11

Registers - PSW l l

Program Status Word is a “bit addressable” 8bit register that has all the flags CY - Carry Flag –

l

AC - Aux. Carry Flag –

l

Carry from D3 to D4. Used for BCD operation

P - Parity Flag – –

l

Set whenever there is a carry in an arithmetic operation

P=1 if A has odd number of 1s Even parity

OV - Overflow Flag –

Set if any arithmetic operation causes an overflow

21-Jan-03

12

Flags - Illustration l

Addition example – –

mov A, #38 add A, #2F

38 + 2F --------67 --------CY = 0 AC = 1 P =1

21-Jan-03

0011 1000 0010 1111 --------------0110 0111 ---------------

13

Registers - SFRs l

l

l l

Control the operation of on-board peripherals Special Function Registers at direct addresses 80H to FFH 8051 Clones may have additional SFRs All registers have an address 21-Jan-03

14

8051 Memory map l l

Separate Code and Data memory Code Memory – – –

l

Data Memory – – –

l

Upto 64K long (some maybe onboard) (0x0000 to 0xFFFF) PSEN is the controlling signal Can store Program only (Read only) Upto 64K long (0x0000 to 0xFFFF) RD/WR are the controlling signals Can store data only (Read and Write)

Internal RAM – –

128 bytes 0x00 to 0x7F (includes register banks) SFRs 0x80 to 0xFF (not all available)

21-Jan-03

15

8051 - Memory Map Memory Type

Start

End

IRAM

0x00

0x7F

Data

0x0000

0xFFFF

RD, WR

movx A, @DPTR

Code

0x0000

0xFFFF

PSEN

movc A,@A+DPTR

SFRs

0x80

0xFF

l l l

Signal

Instruction mov A, xxH mov @Ri

mov A, xxH

Internal ROM is vendor dependant On power-up PC starts at 0000H in ROM space Clones may have internal memory that may be used as both Code+Data 21-Jan-03

16

8051 – Instruction Set l

Data Transfer – –

l

Logical – –

l



Perform arithmetic operations on data add, addc, subb, inc, dec, mul, div

Program control – –

l

Perform logic operations on data anl, orl, xrl, clr, cpl, rl, rlc, rr, rrc, swap

Arithmetic –

l

Move/Copy data from one location to another mov, movc, movx, push, pop, xch, xchd

Control the program flow (jumps, subroutine calls) jmp, ajmp, ljmp, sjmp, jc, jnc, jb, jnb, jbc, jz, jnz, acall, lcall, cjne, djnz, ret, reti

NOP 21-Jan-03

17

8051 – Instruction Set (contd.) l

Read through the instruction set – –

l l

Don’t have to remember all the instructions Don’t have to remember all possible cases

Remember the types of instructions When writing code – –

Write down the operation needed in simple English Lookup the instruction set to see which (combo) of instructions will do the job

21-Jan-03

18

Assembly à Opcode l

Every assembly instruction translates to a unique binary Opcode – –

l

Example1: mov A, #data – – –

l

Can be 1, 2 or 3 bytes long 8051 Family Programmers Guide has a list 2 bytes, 1 cycles 0111 0100 data8 mov A, 0xAA è 0111 0100 1010 10101 è 74 AA

Example2: acall address11 – –

a10 a9 a8 1 0001 a7 a6 a5 a4 a3 a2 a1 a0 acall 0x557 è 101 1 0001 0101 0111 è B1 57

21-Jan-03

19

Assembler Directives l

Assembly statement structure [label:] opcode [operands] [;comment] start: mov A, #D0H ;code starts here

l

Assembler directives Instruct assembler to do a special task – –

ORG xxxxH EQU l



l



count EQU 25

DB l

: define byte, defines allocation of storage DATA1: DATA2:

END

21-Jan-03

: origin, start assembling at xxxxH : define a constant

DB DB

28 “hello world”

: end of assembly file 20

Assembly Design Flow l l

Create the assembly source file test.asm Assemble the asm file C:\> as51 test.asm – Assembler produces error and code list in test.lst – If no errors, assembler produces .obj file

l l l l

Link the .obj files to produce an .abs file Create hex file from the .abs file Most assemblers directly produce the .hex file Download the .hex file onto the board or burn it into an EPROM.

21-Jan-03

21

Assembly Example #1 l

l

Target 8051 dev system – – –

– –

Std 8051 device 2K on-chip ROM running a monitor program 32K external RAM at address 0x0000 to 0x7FFF This RAM is both code and data First 0x30 locations in external RAM is dedicated for the Interrupt Vector Table (IVT)

Program to fill up the first 4 registers in the register bank with some numbers and find their sum

Start:

clearA: Addup:

Done:

21-Jan-03

22

ORG 0x30 ;skip the IVT area mov R0, #10 mov R1, #0A5H mov R2, #1 mov R3, #0x20 mov A, #0 ;now A = 0 add A, R0 ;now A = A + R0 add A, R1 add A, R2 add A, R3 mov R4, A ;store sum in R4 mov DPTR, #7FFF movx @DPTR, A ;store in ext. mem sjmp done ;loop here forever END

Class –2 Review l l l l l l l

What are the different views/models of a uP ? What are the registers available in the 8051 ? What are the functions of the 8051 registers ? What is stack, PC, SFR, PSW/Flags ? What is an instruction set ? What is a memory map ? Why is it needed ? What is an assembly language program ? How does it look ?

21-Jan-03

23

Related Documents

Instr Set Of 8051
November 2019 3
8052 Instr Set
November 2019 4
8051 Instruction Set
June 2020 3
8051
November 2019 12
8051
June 2020 8
8051
November 2019 15