Q. 3.9 of HW3 EE 37 Microcontroller Applications (a) (c) (b) (d) Midterm Review: Miller Chapter -3 -The Stuff That Might Be On the Exam D67 (e) (g) (h) CEC23 (i) (f) (j) (k) (l) (m) EE37/CC/Lecture-Review EE37/CC/Lecture#9 2 Q. 3.9 of HW3 Q. 3.2 of HW3 (o) (n) (r) (p) (q) 7 (s) References 22 5 7 9 6 (q) 23 3 START CMPB #-6 BLT NEXT CMPB #4 BGT NEXT CLRB NEXT SWI/STOP END EE37/CC/Lecture#9 3 EE37/CC/Lecture#9 4
Q. 3.22 of HW3 One version might look like this:. TAB LDAA #$FF TSTB BMI NEXT CLRA NEXT. Chapters -3 Coverage & Format Some multiple choice Some short answer Some quantitative questions EE37/CC/Lecture#9 5 EE37/CC/Lecture#9 6 Various and Sundry Close book/notes The relevant pages (instruction table) of HC Reference Manual can be printed and brought to the exam You can bring your calculators Not really needed Chapter / Lectures 2-4 Number representation (lecture 3) Conversion among: decimal, binary, octal, hexadecimal Signed binary numbers, two s complement Binary Coded Decimal (BCD) Ranges of signed and unsigned numbers Number storage Endian-ness: Little endian vs. Big endian (lecture 5) Memory Systems (lecture 4) What is the address vs. the data? What are the other signals? Read/Write, Timing Fetch/Decode/Execute Cycle (lecture 4) Computer vs. Microprocessor vs. microcontroller (lecture 4) Building blocks of a computer: The four major components of a microprocessor EE37/CC/Lecture#9 7 EE37/CC/Lecture#9 8
Number representation: example Convert 95 into 8-bit binary Convert into a decimal number if it is Unsigned binary 2 2 s complement -45 The range of 8 bits signed number (-28, 27) Extend 2 into a 8-bit signed number 2 The value of in 2 s complement, S&M -3, -5 Memory Organization Memory Organization Questions 68HC 8-bits ( byte)/word Byte-addressable 6-bit address 2 6 (64k) bytes maximum (hexadecimal expression) Big-endian byte-ordering Little-endian bit-ordering EE37/CC/Lecture#9 9 EE37/CC/Lecture#9 Memory Interfacing Number storage: Byte Ordering Illustration N = num. of bits in address = log 2 (num. of words) w = word width = num. of bits in one word Example-Store 4-byte BCD number 2345678 starting in memory location $4. Mem. Big Little Loc. Endian Endian Big endian Least significant byte has highest address. Little endian Least significant byte has lowest address. 4 2 78 4 34 56 42 56 34 43 78 2 EE37/CC/Lecture#9 EE37/CC/Lecture#9 2
Memory Organization-Bit Ordering Four basic components of a computer Which end of the word is labeled bit? Little endian--bit is the least significant bit (rightmost bit). Almost all modern processors, including the 68 use little endian. Big endian--bit is the most significant bit (leftmost bit). Mem. Big Little Big Loc Endian Endian Endian (Byte) (Bit) (Bit) 4 2,, 4 34,, 42 56,, 43 78,, ALU + registers IR EE37/CC/Lecture#9 3 EE37/CC/Lecture#9 4 Chapter 2 / Lectures 5 & 6s & 7 & 8 Register The HC programming model Registers, memory, CCR, PC, etc. Register organization issues number of registers Instructions Logical (AND, OR, EOR, NOT) Shift (Logical, Arithmetic, Roll) Arithmetic Branch Comparison register uniformity 7 5 5 5 A 7 B D X Y 8-bit accumulators 6-bit accumulator Index register Index register Addressing Modes 5 5 SP PC Stack pointer Program counter S X H I N Z V C Condition code register EE37/CC/Lecture#9 5 EE37/CC/Lecture#9 6
Condition code questions Example : + + C= V= N= Z= valid for unsigned? valid for singed? C= V= N= Z= valid for unsigned? valid for singed? EE37/CC/Lecture#9 7 Condition code questions Example 2: A=5, B=-5 R=A+B=? C= V= N= Z= Example 3: A=4, B=-5 R=A+B=? C= V= N= Z= Example 3: A=2, B=36 R=A+B=? C= V= N= Z= EE37/CC/Lecture#9 8 Instructions and Addressing Exercise Load and store instructions direct addressing (8-bit address) extended addressing (6-bit address) immediate data 7A 49 2 27... 3C 54 2 7 3 88 Originally A holds 7D and B holds 6E. Find the contents of A, B and memory after the sequence ldaa #6 A=$ ldab $2 B=$7 staa $ ()=$ ldd $ D=$54 EE37/CC/Lecture#9 9 EE37/CC/Lecture#9 2
Logical operations Logic operations: example and, or, eor rega regb Write assembly software that toggles PORTA bits 3,4 and may be used to isolate a bit, usually for testing Example: anda #$4 isolates bit 2 bits are numbered from at the right and may be used to clear a bit Example: anda #$F7 clears bit 3 the other bits are not affected or may be used to set a bit Example: oraa #$4 sets bit 6 the other bits are not affected EE37/CC/Lecture#9 2 ldaa PORTA eora #$C *#% staa PORTA EE37/CC/Lecture#9 22 68 Shift Instructions For register A asla arithmetic shift left asra arithmetic shift right lsla logical shift left lsra logical shift right rola rotate left rora rotate right Registers B and D and memory have similar instructions. Shifting into carry allows us to check carry bit. 7 6 5 4 3 2 C EE37/CC/Lecture#9 23 Arithmetic operations Arithmetic Operations instructions and results including validity of results Example: Add $8 and $ + = Sum is $8. C = N = V = Z = Unsigned interpretation: 28 + = 29 valid Signed interpretation: -28 ++ = -27 valid EE37/CC/Lecture#9 24
Architecture Example Excise: Loaded Object Program and Data Explain the execution of a 3-Byte Instruction (4 Ticks) using the processor model as shown (slides 22-27 of lecture 5): LDAA C2 Fetch Phase Fetch Opcode, Decode Opcode (need 2 more bytes) and Increment PC-- Tick Fetch 2 nd byte and Increment PC-- Tick 2 Fetch 3 rd byte and Increment PC-- Tick 3 Execute Phase Execute the instruction-- Tick 4 A PC IR B ldaa adda staa stop C2B C2C C2D LDAA ADDA STAA STOP N N2 SUM C2 C2 C22 C23 C24 C25 C26 C27 C28 C29 C2A C2B C2C C2D B6 C2 B BB C2 C B7 C2 D 3F FF 2 29 FF EE37/CC/Lecture#9 25 EE37/CC/Lecture#9 26 Addressing Mode Summary 68HC Operand Formats: Inherent = obvious from the opcode (there is no operand) Immediate = precede value with a # (e.g. #35 #$23) Extended = just write the address (e.g. 266 $A) Direct = just write the address (like extended), but: If the address is <256 Then the assembler chooses direct instead of extended Indexed = write offset, Index-Register (e.g. $AF, X;) Relative = just write the symbolic address instructions using relative addressing have no options obvious from the opcode Addressing example X=$2 Y=$28 A=$45 B=$67 For each of the instruction, specify EA, result, memory location and value: staa 4, x (24)=$45 std $66, y (2E6)=$45, (2E7)=$67 EE37/CC/Lecture#9 27 EE37/CC/Lecture#9 28
Review of instructions Load/store ldaa, ldab, ldd, lds, ldx, ldy staa, stab, std, sts, stx, sty Arithmetic adda, addb, addd suba, subb, subd Logical anda, andb, oraa, orab, eora, eorb Shifts of three types asla, asra, lsla, lsra, rola, rora Comparison and test instructions cmpa cmpb, cpd, cpx, cpy tst (memory), tsta, tstb Branch instructions Bit instructions Increment/decrement EE37/CC/Lecture#9 29 Condition Code and Branch C = Carry-out bit Meaning: C=: Previous instruction had a carry-out C=: Previous instruction didn t have a carry-out Usage: C= Overflow for unsigned arithmetic only Ignore C bit for signed arithmetic Relevant Branch opcodes: BCC: Branch if Carry Clear (C=) BCS: Branch if Carry Set (C=) EE37/CC/Lecture#9 3 Condition Code and Branch V = Overflow bit (2 s complement) Meaning: V=: Previous instruction had an overflow V=: Previous instruction didn t have an overflow Usage: V= Overflow for signed arithmetic only Ignore V bit for unsigned arithmetic Relevant Branch opcodes: BVC: Branch if Overflow Clear (V=) BVS: Branch if Overflow Set (V=) EE37/CC/Lecture#9 3 Condition Code and Branch Z = Zero bit Meaning: Z=: Previous instruction result = Z=: Previous instruction result watch these; they are counter-intuitive Usage: Z= the zero condition is true all bits of the result are zeros Relevant Branch opcodes: BNE: Branch if result not equal to zero (Z=) BEQ: Branch if result is equal to zero (Z=) EE37/CC/Lecture#9 32
Condition Code and Branch N = Negative bit Meaning: N=: Previous instruction result < N=: Previous instruction result Usage: N= Left-hand bit = (sign-bit) Evaluates 2 s complement negative Relevant Branch opcodes: BPL: Branch if result sign is plus (N=) actually branches if result is not-negative BMI: Branch if result sign is minus (N=) Chapter 3 / Lectures 9 & Process of Assembly Language Program Development Labels Rules, what are they used for Assembler Directives (Psuedo-ops) What do they do? How are they different? The Assembler How many passes? Location Counter Symbol Table Be able to hand-assemble individual instructions (probably not whole programs). EE37/CC/Lecture#9 33 EE37/CC/Lecture#9 34