Introduction to Micro Controllers Embedded System Design Department
Introduction to Micro Controllers & Embedded System Design Department of Electrical & Computer Engineering Missouri University of Science & Technology hurson@mst. edu A. R. Hurson 1
Introduction to Micro Controllers & Embedded System Design • Stored Program Machine: A computer with a storage component that may contain both data to be manipulated and instructions to manipulate the data is called a stored program machine. This simply implies that the user is able to change the sequence of operations on the data. • Program: The sequence of operations performed on the data is called a program. More formally, it is a finite set of instructions that specify the operands, operations, and the sequence by which processing has to occur. A. R. Hurson 2
Introduction to Micro Controllers & Embedded System Design • Instruction: An instruction is a group of bits that tells the computer to perform a specific operation. It is composed of two parts: • • Operation part Operand part A. R. Hurson 3
Introduction to Micro Controllers & Embedded System Design • Operation part (operation code) is a group of bits that defines the action to be performed. • For each machine the set of operations is limited and defined. • In general, a machine with n bits as op. code is capable of supporting 2 n distinct operations each having a distinct encoding as op. code. A. R. Hurson 4
Introduction to Micro Controllers & Embedded System Design • Operand part defines the element (s) needed for operation. • Within the scope of a program, besides the op. code, one needs four pieces of information (note majority of operations are binary operations): • 2 operands as sources • 1 operand as a destination • 1 operand to specify the location of the next instruction that should be fetched. A. R. Hurson 5
Introduction to Micro Controllers & Embedded System Design • Depending on how many of these pieces of information are explicitly defined, instructions are grouped into 5 classes: 4, 3, 2, 1, and 0 -address instructions. A. R. Hurson 6
Introduction to Micro Controllers & Embedded System Design • Register addressing • In 8051 programmer has access to eight “working registers” numbered R 0 to R 7. • Three least significant bits of op. code are used to specify a register. • The 8051 assembly language indicates register addressing with the symbol Rn (0 n 7). A. R. Hurson 7
Introduction to Micro Controllers & Embedded System Design • Register addressing • Example ADD A, R 7 11101111 Op. code register Op. code Instruction format A. R. Hurson Register 8
Introduction to Micro Controllers & Embedded System Design • Implied • Some instructions are referring to specific register such as A (accumulator), DPTR (data pointer), PC (program counter), and B register so address bits are not needed. In another words, op. code indicates the register involved in the operation. • Example INC DPTR MUL AB A. R. Hurson 9
Introduction to Micro Controllers & Embedded System Design • Direct addressing allows access to any on-chip variable or hardware register. An additional byte is appended to the op. code specifying the location to be used. • Example MOV P 1, A Op. code Direct addressing Instruction format A. R. Hurson 10
Introduction to Micro Controllers & Embedded System Design • Indirect addressing • In 8051, R 0 and R 1 may operate as a “pointer” register. In this case, the low order bit of op. code indicates which register. • In 8051 assembly language, indirect addressing is identified as “@” preceding either R 0 or R 1. A. R. Hurson 11
Introduction to Micro Controllers & Embedded System Design • Indirect addressing • Example: Assume R 1 contains 40 H and internal memory address 40 H contains 55 H, then the instruction MOV A, @R 1 moves 55 H into the accumulator Op. code Instruction format A. R. Hurson i R 0 or R 1 12
Introduction to Micro Controllers & Embedded System Design • Immediate addressing • In assembly language of 8051, immediate addressing is identified by “#” symbol. The operand may be a numeric constant, a symbolic variable, or an arithmetic expression using constant, symbols, and operators. Assembler calculates the expression and substitutes the result into the instruction. Op. code Immediate data Instruction format A. R. Hurson 13
Introduction to Micro Controllers & Embedded System Design • Immediate addressing • Example: MOV A, #12 • Note: There is just one exception when initializing the data pointer, we need a 16 -bit constant, therefore MOV DPTR, #8000 H is a 3 -byte instruction with a 16 -bit constant 8000 H. A. R. Hurson 14
Introduction to Micro Controllers & Embedded System Design • Relative addressing • This addressing mode is used with certain jump instructions. A relative address is an 8 -bit signed value which is added to the contents of the program counter to form address of the next instruction to be fetched and executed. • Naturally, the range for jump is -128 to +127 locations. Op. code Relative offset Instruction format A. R. Hurson 15
Introduction to Micro Controllers & Embedded System Design • Relative addressing • Example: Assume label THREE represents an instruction at location 1040 H and instruction SJMP THREE is in memory location 1000 H and 1001 H, then the assembler assigns a relative offset of 3 EH as byte-two of the instruction since 1002 H + 3 EH = 1040 H A. R. Hurson 16
Introduction to Micro Controllers & Embedded System Design • Absolute addressing is just used with ACALL and AJMP instructions. These 2 -byte instructions allow branching within the current 2 K page of code memory by providing the 11 least significant bits of destination address in op. code (i. e. , A 10 -A 8 and byte 2 of instruction A 7 -A 0). A 10 -A 8 Op. code A 7 -A 0 Instruction format A. R. Hurson 17
Introduction to Micro Controllers & Embedded System Design • Absolute addressing • The upper five bits of the destination address are the current value of the upper five bits of program counter. Therefore, the next instruction after the branch and the destination instruction must be within the same 2 K page. A. R. Hurson 18
Introduction to Micro Controllers & Embedded System Design • Index addressing uses a base register (either the program counter or the data pointer) and an offset (the accumulator) in forming the effective address for JMP or MOVC instructions. • Example: MOVC A, @A+PC PC or DPTR + ACC = effective address Base register A. R. Hurson Offset 19
- Slides: 19