Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE 3430 – Intro to Microcomputer Systems

Similar presentations


Presentation on theme: "ECE 3430 – Intro to Microcomputer Systems"— Presentation transcript:

1 ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Introduction to Microcomputer Systems University of Colorado at Colorado Springs Lecture #9 Agenda Today 1) The Reset Vector 2) Intro to Flow Charts 3) Multi-Precision Arithmetic 4) BCD Addition Lecture #9 ECE 3430 – Intro to Microcomputer Systems Fall 2009

2 ECE 3430 – Intro to Microcomputer Systems
Reset Vector Reset Vector – When a CPU is reset, what happens? - A RESET is actually an interrupt (interrupts covered later). - Most internal registers are cleared on reset. RAM memory maintains the values last stored to them. - The CPU needs to know where to begin executing code (i.e., what value to initialize the program counter to) after the reset is released. - The code that is executed first should reside in non-volatile memory (after a reset or power up). - A set of memory locations are pre-defined to hold the initial address to be loaded into the program counter upon reset. Since HC11 addresses are 16-bits wide, there are two reserved memory locations. These locations form what is referred to as the reset vector. - In the HC11, it resides at locations $FFFE and $FFFF (16-bit). These memory locations CPU specific. The PC is initialized to the data stored in $FFFE and $FFFF. Lecture #9 ECE 3430 – Intro to Microcomputer Systems Fall 2009

3 ECE 3430 – Intro to Microcomputer Systems
Reset Vector Reset Vector – How do we initialize it? ORG $FFFE RST_VECT: FDB $E000 ; this initializes addresses $FFFE and ; $FFFF to $E0 and $00 respectively Why $E000? It is the beginning of the EEPROM in the Microstamp. In this class, this is where we will originate all of our code. In theory though, we could use any valid 16-bit address. The same type of thing happens in your PC/laptop. Your microprocessor jumps to designated memory locations in EEPROM and determines where to adjust the program counter to. The program counter points to more code stored in EEPROM on the motherboard--this code is referred to as the basic input/output system (BIOS). The BIOS initializes your machine and turns control over to an operating system (if any). Lecture #9 ECE 3430 – Intro to Microcomputer Systems Fall 2009

4 ECE 3430 – Intro to Microcomputer Systems
Reset Vector Reset Vector – - On Reset, the upper byte of the PC will get $E0 and the lower byte will get $ In the HC11 case, PC = $E000. This is where the CPU will READ the first opcode. Ex) Another way to initialize the reset vector: RST_VECT: EQU $FFFE EEPROM: EQU $E ORG RST_VECT RESET: FDB EEPROM ORG EEPROM <code…> Memory $E000 code - - $FFFE $E0 $FFFF $00 Lecture #9 ECE 3430 – Intro to Microcomputer Systems Fall 2009

5 ECE 3430 – Intro to Microcomputer Systems
Into to Flow Charts Flow Charts – Graphical method for designing program flow. This is used for “Designing” programs and also for “Documentation”. Terminal - beginning and end of program (start/stop) Process - what the CPU is “doing” at this point in the execution In/Out - represents data IN or OUT of the program Decision - question in the code--the direction of the code depends on the answer to the question Subroutine - details of the subroutine may be outlined on a separate flowchart On Page Conn place a number/letter in here to differentiate (goto Off Page Conn markers) Lecture #9 ECE 3430 – Intro to Microcomputer Systems Fall 2009

6 We’ll discuss flowcharts in more depth after we discuss
Intro to Flow Charts Ex) Design a program to Add Port B to Port C and store to Port D ORG $E LDAA $04 ; address for Port B LDAB $03 ; address for Port C ABA ; ACCA + ACCB STAA $08 ; address for Port D END START Get B Get C B + C Store Sum We’ll discuss flowcharts in more depth after we discuss branch instructions and conditional code execution. END Lecture #9 ECE 3430 – Intro to Microcomputer Systems Fall 2009

7 Multi-Precision Arithmetic
Multi-Precision Arithmetic (Addition) - Sometimes #’s need more than 1 byte to represent the data. So we need more than just 8-bit arithmetic and representation. Ex) Addition – 8-bit unsigned numbers can go up to 255DEC What if the number is larger? 1 1 $ABCD - RULE: A sum will require the same # of bytes as the operands + a carry bit. + $ The code needs to track the carry bit. $BE01 Write the code to perform the above sum and store in $0040, $0041: LDAA #$CD ; For the LS byte, don’t worry about carry bit. ADDA #$34 ; The instruction ADDA changes the carry bit (see pink book), but doesn’t consider it. STAA $41 ; Store the lower byte in $ LDAA #$AB ; For the MS byte, we need to consider the carry bit from the previous instruction. ADCA #$12 ; ADCA will add the operand and the carry bit (in the CCR). STAA $40 ; Store the upper byte in $ This way we can sequentially read the 2-byte result. Note that the code we write dictates the size of numbers that can be added by the CPU. Lecture #9 ECE 3430 – Intro to Microcomputer Systems Fall 2009

8 Multi-Precision Arithmetic
Multi-Precision Arithmetic (Subtraction) - In subtraction, if we are subtracting a large number from a smaller number, we need to “borrow” from the next higher digit (just like we did in elementary school…) ex) (during 1-5, we “borrow” and make it 11-5) This also occurs in the HC11 CPU. During subtraction, the C-flag is used to indicate if a borrow occurred: C = 1 if a borrow occurred C = 0 if a borrow DID NOT occur $AB12 - $34CD $7645 Write the code to perform the above subtraction and store in $0040, $0041: LDAA #$12 ; For the LS byte, don’t worry about borrow bit. SUBA #$CD ; The instruction SUBA changes the borrow bit (see pink book), but doesn’t consider it. STAA $41 ; Store the lower byte in $ LDAA #$AB ; For the MS byte, we need to consider the borrow bit from the previous instruction. SBCA #$34 ; SBCA will subtract the operand and the borrow bit (in the CCR). STAA $40 ; Store the upper byte in $ This way we can sequentially read the 2-byte result. Note that the code we write dictates the size of numbers that can be subtracted by the CPU. Lecture #9 ECE 3430 – Intro to Microcomputer Systems Fall 2009

9 Multi-Precision Arithmetic
Multi-Precision Arithmetic (Multiplication) - RULE: The product will take 2x the # of bytes of the operands: ($FF) 1 byte x 255 ($FF) 1 byte ,025 ($FE01) 2 bytes - As previously discussed, the HC11 provides a MUL instruction to perform 8-bit, unsigned multiplication: A x B = D (A=upper, B=lower) Ex) $45 = 69 LDAA #$45 x $24 = 36 LDAB #$24 $ MUL $8A STD <somewhere in memory> $09B … To continue the expansion use the algorithm of Sum of Partial Products (see page 59 in text). With enough memory and time, the HC11 can multiply numbers of any size. Lecture #9 ECE 3430 – Intro to Microcomputer Systems Fall 2009

10 Multi-Precision Arithmetic
Multi-Precision Arithmetic (Integer Division) As discussed previously, the HC11 provides two division instructions (IDIV, FDIV): 16 bit quotient remainder IDIV = Unsigned Integer Divide D = X, D X This instruction divides ACCD by INDX and stores the quotient in X and the remainder in D. Ex) $09 = quotient = $4 (INDX), remainder = $1 (ACCD) $02 (easy example) LDD #$0009 LDX #$0002 IDIV STX $40 STD $42 Techniques do exist to extend division beyond 16-bits—but that is beyond the scope of this course. Memory $0040 $00 $0041 $04 $0042 $00 $0043 $01 Lecture #9 ECE 3430 – Intro to Microcomputer Systems Fall 2009

11 Multi-Precision Arithmetic
Multi-Precision Arithmetic (Fractional Division) - The HC11 provides “unsigned fractional division” as well (FDIV). - The fractional point is assumed to be to the left of the 15th bit in both the numerator and denominator quotient remainder D = X, D X - The numerator is expected to be less than the denominator. - If a “divide by zero” or “overflow” occurs, the quotient is set to $FFFF (i.e., the denominator < numerator results in an operation where the fractional point isn’t where we expect it the instruction can’t handle this) Ex) $ = ACCD ; the code gets pretty sophisticated, you need a BSEE! $ = INDX You will not likely use this instruction very often (if ever)—but it is useful in some complex multi-precision operations. Lecture #9 ECE 3430 – Intro to Microcomputer Systems Fall 2009

12 Multi-Precision Arithmetic
Although the HC11 does not natively support floating point operations, it is possible to write code using the existing HC11 instructions to pull off floating point operations—but it is not easy! Any mathematical operation can be performed on the HC11 with enough code ingenuity. When a uC or uP lacks an instruction to perform a specific operation, the engineer has to use existing operations to pull off more complex operations. In lab 4 this week you will exercise addition, subtraction, multiplication, and division—and output results to the host PC (through the terminal program). Lecture #9 ECE 3430 – Intro to Microcomputer Systems Fall 2009

13 Multi-Precision Arithmetic
Multi-Precision Arithmetic (BCD Addition) - If we are using BCD, traditional addition doesn’t work. In BCD, think of each hex digit as a decimal digit $ correct answer in BCD is $106. Traditional addition only considers $ an 8-bit addition carry. In BCD we need to consider a 4-bit addition carry. $A0 - The solution is to add $6 to every nibble sum greater than $9 and to every nibble-sum that generated a 4-bit carry: $ = When a nibble addition results in “$A” or greater, we add $ $ $9 + $7 generated a 4-bit carry, so we add $6 to it. $A $ $ The CPU needs to monitor the 4-bit carry. - The “H flag” in the CCR does this (Half Carry Bit). - The HC11 provides an instruction to accommodate BCD. DAA = “Decimal Adjust ACCA” Only works for BCD additions The numbers must be BCD to begin with. Ex) LDAA $00 ADDA $01 ; DAA does two things: DAA ; 1) adds $6 to each nibble that is $A or greater. STAA $02 ; 2) checks the H-flag and adds $6 if necessary. Lecture #9 ECE 3430 – Intro to Microcomputer Systems Fall 2009

14 Multi-Precision Arithmetic
The LDAA, ADDA, DAA can be continued in a loop working towards the most-significant digits. However, the ADDA would need to be replaced with the ADCA instruction to account for the carry. BCD subtraction is not supported natively by the HC11. Only the ABA, ADDA, and ADCA instructions modify the H flag in the condition-code register. BCD subtraction involves similar operations to BCD addition: If a borrow occurs or the BCD nibble (decimal digit) is greater than or equal to 10 ($A), 6 ($6) is subtracted from the nibble. BCD multiplication and BCD division algorithms exist—but are pretty complicated. There are both packed and unpacked BCD formats. In unpacked BCD, each decimal digit is represented by 8 bits (1 byte). In packed BCD (as we have discussed in this presentation), each decimal digit is represented by 4 bits (1 nibble). Lecture #9 ECE 3430 – Intro to Microcomputer Systems Fall 2009

15 Multi-Precision Arithmetic
Addition and subtraction can easily be pulled off using both packed and unpacked BCD formats. Multiplication and division require an unpacked BCD format. Lecture #9 ECE 3430 – Intro to Microcomputer Systems Fall 2009


Download ppt "ECE 3430 – Intro to Microcomputer Systems"

Similar presentations


Ads by Google