Operations:

Syntax:

Operation:

Operands:

Program Counter:

Opcode

Comment

Stack

SPM

PS(RAMPZ:Z) = 0xffff

None

PC = PC + 1

1001010111101000

Erase program memory page

SPM

PS(RAMPZ:Z) = R1:R0

None

PC = PC + 1

1001010111101000

Write to program memory word(1)

SPM

PS(RAMPZ:Z) = R1:R0

None

PC = PC + 1

1001010111101000

Load Page Buffer(2)

SPM

PS(RAMPZ:Z) = BUFFER

None

PC = PC + 1

1001010111101000

Write Page Buffer to program memory(2)

SPM Z+

PS(RAMPZ:Z) = 0xfff, Z = Z + 2

None

PC = PC + 1

1001010111111000

Erase program memory page, Z post incremented

SPM Z+

PS(RAMPZ:Z) = R1:R0, Z = Z + 2

None

PC = PC + 1

1001010111111000

Write to program memory word, Z post incremented(1)

SPM Z+

PS(RAMPZ:Z) = R1:R0, Z = Z + 2

None

PC = PC + 1

1001010111111000

Load Page Buffer, Z post incremented(2)

SPM Z+

PS(RAMPZ:Z) =BUFFER, Z = Z + 2

None

PC = PC + 1

1001010111111000

Write Page Buffer to program memory, Z post incremented(2)

Description

SPM can be used to erase a page in the program memory and to write a page in the program memory (that is already erased). In some devices, the program memory can be written one word at a time. In other devices, an entire page can be programmed simultaneously after first filling a temporary page buffer. In all cases, the program memory must be erased one page at a time. When erasing the program memory, the RAMPZ and Z-register are used as page address. When writing the program memory, the RAMPZ and Z-register are used as page or word address, and the R1:R0 register pair is used as data(1). The Flash is word-accessed for code space write operations, so the least

significant bit of the RAMPZ register concatenated with the Z register should be set to ‘0'.

Refer to the device documentation for a detailed description of SPM usage. This instruction can address the entire program memory.

The SPM instruction is not available on all devices. Refer to Appendix A.

Note: 1. R1 determines the instruction high byte, and R0 determines the instruction low byte.

Notes:

1.

Not all devices can write directly to program memory, see device data sheet for detailed description of SPM usage.

2.

Not all devices have a page buffer, see device data sheet for detailed description of SPM usage.

Status Register (SREG) and Boolean Formula

I

T

H

S

V

N

Z

C

Words

1 (2 bytes)

Table Cycles

Name

Cycles

i-iv

v-viii

AVRe

N/A

N/A

AVRxm

-(1)

-(1)

AVRxt

-(1)

-(1)

AVRrc

N/A

N/A

Note:

1.

Varies with the programming time of the device.