Doc Bot

Download | Tutorials | Instruction Set | Hardware Reference
Introduction | About Doc Bot | Site Map | Search | Use License | Contact Us
Download
Screenshots
Table Of Contents | Addressing Modes | Memory Model | External Ports | Instruction Set | Hardware Reference | Turn Cycles | File format
Table Of Contents | Introduction | Types Of Memory | Special Function Registers | Basic Registers | Addressing Modes | Program Flow | Timers | External Ports | Interrupts | Power Control Modes | Hardware Components
Table Of Contents | Calculate Square Roots | Safe Division

Documentation

small logo

Memory Model

The microcontroller's architecture is sequential and has a word size of 16 bits, the unit of address resolution is this 16-bit word and memory is word-addressable. This means that every memory address has a size of one word, which is 2 bytes or 16 bits. There are two memory segments, the main memory where data and instructions (programs) are stored, and the internal memory used for internal calculations where registers, timers and the stack reside. Given the word size of 16 bits, there can be a maximum of 65,535 main memory addresses, which are all directly acessible by the microcontroller; at 2 bytes each, that means main memory actually occupates 128 Kb. Code and data are all stored on the same memory segment, the main memory, though registers and the stack use a separate internal memory. The 16-bit word is used for all internal calculations, which means that unsigned integers have a range of 0 to 65,535 and signed integers, handled using two's complement architecture, have a range of -32,768 to 32,767.

The microcontroller uses a von Neumann sequential architecture, making it a stored-program computer. This means that the microcontroller keeps its programmed instructions, as well as its data, in read-write, random-access main memory, allowing programs to modify themselves by simply overwritting the pertinent main memory addresses. Most other operations, like external port input/output operations and some calculations, are handled through internal memory addresses, called registers.

Each instruction is stored in a main memory address and processed sequentially by the microcontroller. Each instruction can take up to two operands, the actual number of operands being dictated by the instruction itself, which are stored in the next memory addresses. Every instruction is thus a 2-byte number, or opcode, where the most significant (or first) byte dictates the general instruction to be executed, and the least significant (or second) byte dictates the addressing modes of each of its operands, if any.

To briefly recap, instruction opcodes are mapped as follows:

  • Most significant (first) byte is the instruction's general opcode.
  • Least significant (second) byte is the addressing mode of the operands:
    • Left-most 4 bits are the addressing mode of the first operand.
    • Right-most 4 bits are the addressing mode of the second operand.

Addressing modes of the operands on the least significant byte are coded as follows:

  • 0x0 - No Operand
  • 0x1 - Immediate
  • 0x2 - Direct
  • 0x3 - Indirect
  • 0x4 - Direct Relative
  • 0x5 - Indirect Relative
  • 0x6 - Register Direct
  • 0x7 - Register Indirect
  • 0x8 - Bit Addressing

For example, in instruction 0x0120 0x65F5, the instruction's general opcode is 0x01, the first operand is direct (0x2) and there is no second operand (0x0).

Some example opcodes
OpcodeAssembly language
0x0120 0x65F5JMP &0x65F5
0x7631 0xD390 0x02B1MOV @0xD390 #0x02B1
0x2465 0x0003 0x0009ADD R03 @$0x0009
Introduction | About Doc Bot | Site Map | Search | Use License | Contact Us
©2009 Daniel Julivert