25
8-bit 8-bit microcontrolle microcontrolle rs rs

04_Data Handling Instructions

  • Upload
    neeraj

  • View
    227

  • Download
    0

Embed Size (px)

DESCRIPTION

microcontroller

Citation preview

Page 1: 04_Data Handling Instructions

8-bit 8-bit microcontrollersmicrocontrollers

Page 2: 04_Data Handling Instructions

Agenda..

Assembler Directives. Addressing modes Instruction Set Moving data.

Page 3: 04_Data Handling Instructions

Assembler Directives..

The directive are used in assembly languages which set the direction of the program. these are also called pseudo codes because it is written for assembler not for controller. there are mainly 3 directive for8051 ORG          ; to set the origin address of the program. for e.g.    ORG 0010HEQU          ; it is used to set some constant value in data label. for e.g.  temp EQU 50HEND          ; this indicates to assembler that the code is end here

..

Page 4: 04_Data Handling Instructions

EQU & SET directives assign a numeric value or register symbol to the specified symbol name.Symbols defined with EQU may not have been previously defined and may not be redefined by any means..

The SET directive allows later redefinition of symbols.

Symbol EQU Register t EQU R0

Symbol SET Register t EQU R1

CODE (ffff),DATA(ram,sfrs)IDATA(0-255),XDATA(ffff)

Page 5: 04_Data Handling Instructions

Assembler Directives..

ORG & END assembler directive. ORG is used to specify a value for the

currently active segment’s location counter.

It can be used only when the location counter needs to be changed.

Examples..ORG 0000h,ORG 0100h

Page 6: 04_Data Handling Instructions

END directive signals the end of assembly module.

Any text that appears after the END directive is ignored.

* There is no instruction for END

Page 7: 04_Data Handling Instructions

Addressing Modes…

The various ways of accessing data are called addressing modes. The data could be in a register or in memory, or be provided as an immediate value.

1. Immediate Addressing

2. Register Addressing

3. Direct Addressing

4. Indirect Addressing

5. Indexed Addressing

Page 8: 04_Data Handling Instructions

Immediate Addressing Mode…

Simplest way to get data to a destination is to make the source of the data part of the opcode.The data source is then immediately available as a part of the instruction.

Mnemonic for immediate data is MOV

MOV A,#n MOV A,#0F1h

MOV Rr,#n MOV R3,#1Ch

MOV DPTR,#nn MOV DPTR,#0ABBCh

Page 9: 04_Data Handling Instructions

Mov DPTR,#2550H

is same as

• Mov DPL,#50H

• Mov DPH,#25H

Page 10: 04_Data Handling Instructions

Source operand is constant. Immediate data must be preceded by the

pound sign (#). This mode can be used to load information

into any of the registers, including the DPTR register and also to the ports.

It is fast but not very flexible.

Page 11: 04_Data Handling Instructions

Register Addressing Mode…

Registers are used as a part of opcode mnemonic as sources or destinations of data.

MOV A, Rr MOV A, R0

MOV Rr, A MOV R0,A

Page 12: 04_Data Handling Instructions

Source and destination registers must match in size

e.g. Mov DPTR, A is invalid Movement of data between Rr registers is

not allowed,

i.e. Mov R4, R7 is invalid.

Page 13: 04_Data Handling Instructions

Direct Addressing Mode…

•The value to be stored in memory is obtained by directly retrieving it from another memory location.

•Also, it is important to note that when using direct addressing any instruction which refers to an address between 00h and 7Fh is referring to Internal Memory. Any instruction which refers to an address between 80h and FFh is referring to the SFR control registers that control the 8051 microcontroller itself.

Page 14: 04_Data Handling Instructions

MOV A, add MOV A, 80h

MOV add, A MOV 80h, A

MOV add, Rr MOV 8Ch, R2

MOV Rr, add MOV R2, 10h

MOV add1, add2 MOV 03h, 01h

Page 15: 04_Data Handling Instructions

Indirect Addressing Mode…

•Indirect addressing is a very powerful addressing mode which in many cases provides an exceptional level of flexibility.

•Indirect addressing always refers to Internal RAM; it never refers to an SFR.

•It uses a register to hold the actual address that will finally be used in the data move.

•Indirect addressing for MOV opcodes uses Register R0/R1 (often called data pointer) to hold the address of one of the data locations. Registers R2 to R7 are not allowed.

Page 16: 04_Data Handling Instructions

@…

MOV @Rp, #n MOV @R1, #11

MOV @Rp, add MOV @R1, 11h

MOV @Rp, A MOV @R1, A

MOV add, @Rp MOV 11h, @R1

MOV A, @Rp MOV A, @R1

Only registers R0 & R1 can be used for indirect addressing…

Page 17: 04_Data Handling Instructions

Indexed Addressing Indexed addressing mode is widely used in

accessing data elements of look-up table entries located in the program ROM space of the 8051. The instruction used for this purpose is “MOVC A, A+DPTR”.

The “C” means code.The 16 bit register DPTR and register A are

used to form the address of the data element stored in on-chip ROM.

Lets take a closer look…

Page 18: 04_Data Handling Instructions

External Data Moves…

•Opcodes that access this external memory always use indirect addressing mode.

@…

•R0, R1 are used.

•DPTR has 16 bit width.

•All external moves involve A

•When moving data from internal or external ROM use C.

Page 19: 04_Data Handling Instructions

A

R0 or R1

DPTR

DPTR+A

PC+A

Ext. RAM

Int.&

Ext.ROM

Data bus

MOVX @Rp

MOVX @DPTR

MOVC A, @A+DPTR

MOVC A, @A+PC

Page 20: 04_Data Handling Instructions

External Data Moves..(contd..)

MOVX A, @Rp

contents of external address in Rp to A

MOVX a, @DPTR

contents of external address in DPTR to A

MOVX @Rp, A…

MOVX @DPTR, A…

Page 21: 04_Data Handling Instructions

Code Memory Data Moves…

MOVC A,@A+DPTR

Code byte found at ROM address formed by a+dptr to A

MOVC A,@A+PC

Code byte found at ROM address formed by a+pc to A

*All data moved from code memory to A

Page 22: 04_Data Handling Instructions

Push & Pop Opcodes…

Push & Pop opcodes specify the direct address of the data

Data moves between internal RAM(stack) & direct address.

A PUSH opcode copies data from the source address to the stack.SP is incremented by 1 before the data is copied to the internal RAM location contained in SP.

Page 23: 04_Data Handling Instructions

A POP Opcode copies data from the stack to the destination address. SP is decremented by 1 after data is copied from the stack RAM address to the direct destination .

PUSH add : inc SP, copy data in add to int.ram add in SP.

POP add : copy data from internal RAM address contained in SP to add, dec SP

Page 24: 04_Data Handling Instructions

Data exchanges

Exchange instructions move data in two directions: from source to destination and from destination to source.

All addressing modes except immediate may be used in XCH instructions.’

All exchanges are internal to 8051. All exchanges use register A.

Page 25: 04_Data Handling Instructions

XCH A, Rr Exchange the data between register Rr and A

XCH A, add Exchange the data between add and A

XCH A, @Rp Exchange the data between A & address in Rp

XCHD A, @Rp Exchange lower nibble between A & address in Rp.