130 likes | 136 Views
ECE 3430 – Introduction to Microcomputer Systems University of Colorado at Colorado Springs. Lecture #4 Agenda Today More on the LOAD Instructions Big Endian vs. Little Endian HC11 Addressing Modes Announcements Homework #1 due today. Hand it to me before you leave.
E N D
ECE 3430 – Introduction to Microcomputer SystemsUniversity of Colorado at Colorado Springs Lecture #4 Agenda Today • More on the LOAD Instructions • Big Endian vs. Little Endian • HC11 Addressing Modes Announcements • Homework #1 due today. Hand it to me before you leave. • Homework #2 available on the web page. Due in one week. ECE 3430 – Intro to Microcomputer Systems Fall 2009
The LOAD Instruction LOAD An HC11 instruction that moves information into the internal registers of the CPU (A,B,D,X,Y,SP). Where the “information” comes from depends on theaddressing mode. The addressing mode is encoded in the instruction opcode. Recall operands provide additional information needed by an instruction. The HC11 has 6 addressing modes. We will use the LOAD instruction to illustrate the first four: 1) Immediate (operand provides the data) 2) Direct (operand provides memory location of data) 3) Extended (operand provides memory location of data) 4) Indexed (operand provides offset to memory location relative to value stored in the X or Y index register) 5) Inherent (no operands used) 6) Relative (operand provides address relative to current value stored in PC register) ECE 3430 – Intro to Microcomputer Systems Fall 2009
Big Endian vs. Little Endian M($0000)=$12 Suppose I wanted to do two 16-bit loads from memory locations $0000 and $0002… Big Endian (HC11 and Motorola/Freescale Architectures): After a 16-bit load from $0000, I would see in CPU registers: $1234 After a 16-bit load from $0002, I would see in CPU registers: $5678 Little Endian (Intel Architectures): After a 16-bit load from $0000, I would see in CPU registers: $3412 After a 16-bit load from $0002, I would see in CPU registers: $7856 • Endian-ness applies to all memory accesses greater than 8-bits (i.e. 16-bit, 32-bit, 64-bit, 128-bit) • Generally speaking, higher-level programmers are insulated from these architectural differences. M($0001)=$34 M($0002)=$56 M($0003)=$78 ECE 3430 – Intro to Microcomputer Systems Fall 2009
Addressing Modes Immediate Addressing – The operand of the instruction is the “actual data” (IMM) to be loaded into a register. The “#” sign indicates to the cross-assembler that “immediate addressing” is intended. Ex) LDAA #%10101010 ; this instruction will put %10101010 into accumulator A LDD #%1010101001010101 ; this instruction will put %1010101001010101 into accumulator D ; overwriting what was stored in A and B Mnemonic Machine code (LDAA): $86 $AA Machine code (LDD): $CC $AA $55 Opcodes Operands Memory $0000 $86 $0001 $AA $0002 $CC $0003 $AA $0004 $55 Unique code to HC11, the control unit in the CPU decodes opcodes and knows what to do (i.e. put $AA into ACCA or put $AA55 into ACCD) How it looksin memory ECE 3430 – Intro to Microcomputer Systems Fall 2009
Addressing Modes Direct Addressing – The operand of the instruction is the “address” of where(DIR) the data is located in memory. Direct uses only 1 byte in memory to indicate the address. This means that the data must reside between $00 - $FF (the upper byte of the address is assumed to be $00). Ex) LDAA $00 ; this instruction will put the contents of memory location $0000 into ACCA: ; ACCA = M($0000) LDX $00 ; this instruction will put the contents of memory locations $0000 and $0001 into ; the upper and lower parts of index register X: ; X(high) = M($0000), X(low) = M($0001) Mnemonics Machine code (LDAA): $96 $00 Machine code (LDX): $DE $00 Memory $0000 $12 $0001 $34 $e000 $96 $e001 $00 $e002 $DE $e003 $00 ACCA = $12after this instruction is executed, Opcodes Operands X = $1234after this instruction is executed The control unit knows that $96 and $DE mean direct addressing on ACCA and index register X respectively ECE 3430 – Intro to Microcomputer Systems Fall 2009
Addressing Modes Extended Addressing – This is the same as direct except that 2 bytes are used(EXT) for the “address” of where the data is to be loaded from. With two bytes of memory, the data can be located from locations $0000 to $FFFF in memory. Ex) LDAA $FFFF ; this instruction will put the contents of memory location ; $FFFF into ACCA: ACCA = M($FFFF) LDY $FFFE ; this instruction will put the contents of ; memory location $FFFE and $FFFF into index ; register Y: ; Y(high) = M($FFFE), Y(low) = M($FFFF) Mnemonic Machine code (LDAA): $B6 $FF $FF Machine code (LDY): $18 $FE $FF $FE Memory $0000 $B6 $0001 $FF $0002 $FF $0003 $18 $0004 $FE $0005 $FF $0006 $FE $FFFE $12 $FFFF $34 ACCA = $34 and INDY = $1234after these instructions are executed Opcodes Operands The control unit knows to use extended addressing mode. ECE 3430 – Intro to Microcomputer Systems Fall 2009
Addressing Modes Indexed Addressing – The contents of index registers X and Y are added to the (INDX, INDY) operand of the instruction to form the effective address. The operand acts as an “offset” from where X and Y are pointing in memory. The X or Y registers need to be initialized. Ex) LDX #$0100 ; initializes the X register to $0100 using immediate addressingLDD 2,X ; loads accumulator D with the contents of memory location $0102 and ; $0103: ; ACCA = M($0102), ACCB = M($0103) Mnemonics Machine code (LDD): $EC $02 Memory $0000 $EC $0001 $02 $0101 - $0102 $56 $0103 $78 Opcode Operand ACCD = $5678after this instruction is executed The control unit knows that $EC means to load ACCD using index register X ECE 3430 – Intro to Microcomputer Systems Fall 2009
Addressing Modes Inherent Addressing – The opcode contains all of the information needed by the (INH) instruction. Loading does not use this addressing mode. Instructions that use this addressing mode are usually doing atomic operations on CPU accumulators/registers. Ex) ABA ; adds contents of ACCA to contents of ACCB and puts the result ; in ACCA (A = A+B) CLI ; clears the I bit in the condition code register LSLB ; shifts the bits in ACCB one position to the left (shifts in a 0) NEGA ; take two’s complement of ACCA COMB ; take one’s complement of ACCB The machine code for each instruction will contain one or more opcodes—but no operands! Machine code (ABA): $1B Machine code (CLI): $0E etc. ECE 3430 – Intro to Microcomputer Systems Fall 2009
Addressing Modes Relative Addressing – The operand gives an offset that is added to the memory(REL) location of the next instruction’s opcode. In the HC11, this addressing mode is used only with branch instructions. A branch is where the program counter is set to something besides PC+1 (covered later). The offset is an 8-bit signed number. This means the “effective address” can be from –128 to +127 memory locations from the current address. Ex) BRA $01 ; This will “branch” positive 1 memory location Machine code: $20 $01 Memory PC $0000 $20 $0001 $01 $0002 - $0003 - Opcode Operand PC = $0003after the instruction isexecuted. The PC is set to $0002 after the opcode and operand are loaded out of memory. The offset ($01 = +1) is relative to $0002. ECE 3430 – Intro to Microcomputer Systems Fall 2009
Addressing Modes Relative Addressing – Suppose the microcontroller was finished executing (REL) code and the program counter needed to be trapped (so that the HC11 will not continue plowing through uninitialized memory. One could call the STOP instruction or branch back to the last instruction: Ex) BRA $FE ; This will “branch” negative 2 memory locations Machine code: $20 $FE Opcode Operand Memory The PC is set to $E012 after the opcode and operand are loaded out of memory. The offset ($FE = -2) is relative to $E012. The code execution is effectively stopped now—but the uC is still using power. PC $E010 $20 $E011 $FE $E012 - $E013 - PC = $E010after the instruction isexecuted. ECE 3430 – Intro to Microcomputer Systems Fall 2009
Addressing Modes Relative Addressing – These offsets are really confusing! Fortunately (REL) assemblers make use of labels and these labels allow the assembler to automatically calculate the correct offsets for you! This will be discussed later. Ex) DONE: BRA DONE DONE is a label which labels the BRA instruction. The label can be called just about anything. The above is valid assembly syntax and will be converted the correct machine code by the assembler. ECE 3430 – Intro to Microcomputer Systems Fall 2009
The LOAD Instructions (Review) LOAD Instructions – The HC11 has LOAD instructions to put information within its internal registers and accumulators. There are instructions for all of the internal registers. Each accumulator can be loaded using the addressing modes described earlier. See the HC11 Programmer’s ReferenceGuide (the pink book) for specifics.LDAA ; load accumulator A (8-bit)LDAB ; load accumulator B (8-bit)LDD ; load accumulator D (16-bit, LDD #$1234, ACCA=$12, ACCB=$34)LDS ; load stack pointer (16-bit) LDX ; load index register X (16-bit)LDY ; load index register Y (16-bit) NOTE:The condition code register (CCR) and program counter (PC) are not loaded with load instructions. The PC is initialized via reset interrupt vectors (discussed later) and the CCR can be altered by transferring contents to and from ACCA using special TPA/TAP instructions—but generally other instructions indirectly change the CCR. ECE 3430 – Intro to Microcomputer Systems Fall 2009
To Find Out More About HC11 Instructions See the pink book. A large table runs length-wise and consumes many pages. Here you will find the entire HC11 instruction set (alphabetized) along with the opcodes for each instruction (for all supported addressing modes). You will need to reference this when doing homework #2. ECE 3430 – Intro to Microcomputer Systems Fall 2009