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 #11 Agenda Today More Bit-Wise Instructions The Stack (Push, Pull) and the Stack Pointer Lecture #11 ECE 3430 – Intro to Microcomputer Systems Fall 2009

2 ECE 3430 – Intro to Microcomputer Systems
More Instructions Decrement and Increment - Often used in loops to adjust “counters” - These add or subtract 1 from the destination (effective address) DECA ; A = A – 1 INCA ; A = A + 1 DECB ; B = B – 1 INCB ; B = B + 1 DEC operand ; M() = M() – 1 INC operand ; M() = M() + 1 DES ; SP = SP – 1 INS ; SP = SP + 1 DEX ; X = X – 1 INX ; X = X + 1 DEY ; Y = Y – 1 INY ; Y = Y + 1 Ex) COUNT EQU 10 EEPROM EQU $E ORG EEPROM LDAA #COUNT ; initialize loop counter LOOP: DECA ; loop 10 times BNE LOOP DONE: BRA DONE END Lecture #11 ECE 3430 – Intro to Microcomputer Systems Fall 2009

3 ECE 3430 – Intro to Microcomputer Systems
More Instructions Arithmetic Shift - used to shift bits - note the characteristics of the end bits LEFT ASL <operand> ASLA ASLB Note: LSB is filled with ‘0’, MSB shift into carry ASLD A B RIGHT ASR <operand> ASRA ASRB Note: MSB is shifted into itself LSB is shifted into carry No ACCD shift right (no ASRD) C 7  0 C 7  0 7  0 7 0 C Lecture #11 ECE 3430 – Intro to Microcomputer Systems Fall 2009

4 ECE 3430 – Intro to Microcomputer Systems
More Instructions Logical Shift - used to shift bits - note the characteristics of the end bits, different from arithmetic shifts LEFT LSL <operand> LSLA LSLB Note: LSB is filled with ‘0’, MSB shift into carry LSLD RIGHT LSR <operand> LSRA LSRB Note: 0 is shifted into MSB LSB is shifted into carry LSRD C 7  0 C 7  0 7  0 A B 7 0 C 7  0 7  0 C A B Lecture #11 ECE 3430 – Intro to Microcomputer Systems Fall 2009

5 ECE 3430 – Intro to Microcomputer Systems
More Instructions Rotate - used to rotate bits - note the characteristics of the end bits, different from arithmetic and logical shifts LEFT ROL <operand> ROLA ROLB Note: full loop, MSB goes to carry RIGHT ROR <operand> RORA RORB Note: full loop, carry goes to MSB 7  0 C 7 0 C Lecture #11 ECE 3430 – Intro to Microcomputer Systems Fall 2009

6 ECE 3430 – Intro to Microcomputer Systems
More Instructions Example What are the contents of ACCA after each instruction? LDAA #% ACCA Carry ASRA % LSRA % RORA % What addressing mode are these instructions? INHERENT What CCR bits are altered and how? N Z V C ASRA ‡ ‡ ‡ ‡ LSRA 0 ‡ ‡ ‡ NOTE: because MSB always gets = RORA ‡ ‡ ‡ ‡ ‡ = set to one or cleared to zero depending on run-time circumstances Lecture #11 ECE 3430 – Intro to Microcomputer Systems Fall 2009

7 ECE 3430 – Intro to Microcomputer Systems
More Instructions 1’s and 2’s compliment NEG <operand>  2’s compliment NEGA NEGB COM <operand>  bitwise inversion, 1’s compliment COMA COMB LDAA #% NEGA  A = % COMA  A = % Lecture #11 ECE 3430 – Intro to Microcomputer Systems Fall 2009

8 The Stack - This is just managed RAM. The “stack” can live anywhere in RAM. - This is a last in, first out (LIFO) data structure. - This is a first in, last out (FILO) data structure. - Items can only be added or removed from the top of the stack. - Conceptually like a stack of cafeteria trays or a PEZ dispenser. PUSH – inserting something onto the TOP of the STACK PULL – removing something from the TOP of the STACK Ex) PUSH $11, $22, $33 PULL, we will receive $33, $22, $11 in that order TOP Last In This structure is useful because the order of data is inherently kept. We don’t need to worry about setting up dedicated memory for each byte. This is also a necessary structure for subroutines to work. First In BOTTOM TOP $33 $22 $11 Lecture #11 ECE 3430 – Intro to Microcomputer Systems Fall 2009

9 The Stack What the stack really is: - A section of memory with an address pointer (stack pointer = SP in CPU). - The SP contains the address of the empty space on top of the stack. - In the HC11, the SP is decremented as information is PUSHED. - In the HC11, the SP is incremented as information is PULLED. - The actual value of the SP is the location of where the next piece of data would be PUSHED. - We define where to place the stack data structure (using LDS instruction). - The stack is variable in size and only limited by RAM availability. - The standard is to place the STACK at the end of RAM (for MicroStamp, $00FF) The HC11 provides instructions to manipulate the stack. - How do we initialize the stack? LDS #$00FF RAM Keep global variables close to the beginning of RAM $0040 : $00FF Initialize stack at the end of RAM Lecture #11 ECE 3430 – Intro to Microcomputer Systems Fall 2009

10 The Stack Stack Overflow - If we push too much information onto the stack, it may start overriding data stored in pre-defined variables. - Since there is no operating system running on our HC11, you have to be the memory manager! HC11 Stack Instructions PSHA PULA LDS TSX PSHB PULB DES TSY PSHX PULX INS TXS PSHY PULY STS TYS RAM variables $40 : $FF Stack creeps backwards through RAM as data is pushed onto it Lecture #11 ECE 3430 – Intro to Microcomputer Systems Fall 2009

11 ECE 3430 – Intro to Microcomputer Systems
The Stack Example Remember that the SP points to the address of where the ‘next piece of data’ goes! LDS #$00FF LDAA #$AA LDAB #$BB PSHA PSHB PULA ; ACCA = $BB PULB ; ACCB = $AA NOTE: The data in RAM is not actually erased! $00FF SP xx $00FE $00FF SP xx $AA $00FD $00FE $00FF SP xx $BB $AA $00FE $00FF SP xx $AA $00FF SP xx Lecture #11 ECE 3430 – Intro to Microcomputer Systems Fall 2009

12 ECE 3430 – Intro to Microcomputer Systems
The Stack Example Program using the STACK Sample port D 10 times as fast as you can, then sum the result (in 2 loops) EEPROM EQU $E000 STACK EQU $00FF PORTD EQU $0008 RAM EQU $0040 COUNT EQU ORG RAM RESULT RMB 1 ; allocate memory in RAM to hold result ORG EEPROM ; start code at beginning of EEPROM LDS #STACK ; initialize stack point to end of RAM LDAB #COUNT ; initialize loop counter CLR RESULT ; initialize result to zero SAMPLE: LDAA PORTD ; sample data on port D PSHA ; store the sample on the stack DECB ; decrement loop counter BNE SAMPLE ; perform this task 10 times …continued  Lecture #11 ECE 3430 – Intro to Microcomputer Systems Fall 2009

13 ECE 3430 – Intro to Microcomputer Systems
The Stack LDAB #COUNT ; reinitialize the loop counter SUM: PULA ; bring in the information off the top of the stack ADDA RESULT ; continually sum this with RESULT (first pass, RESULT=0) STAA RESULT ; store continual sum in RESULT DECB ; decrement loop counter BNE SUM ; do this 10 times DONE: BRA DONE END When the program finishes, the sum of the 10 samples is in RESULT. What is the value of SP after the “sample loop” completes? What is the value of SP after the “sum loop” completes? Did stack overflow occur? How could it have occurred? Lecture #11 ECE 3430 – Intro to Microcomputer Systems Fall 2009

14 ECE 3430 – Intro to Microcomputer Systems
The Stack LDAB #COUNT ; reinitialize the loop counter SUM: PULA ; bring in the information off the top of the stack ADDA RESULT ; continually sum this with RESULT (first pass, RESULT=0) STAA RESULT ; store continual sum in RESULT DECB ; decrement loop counter BNE SUM ; do this 10 times DONE: BRA DONE END When the program finishes, the sum of the 10 samples is in RESULT. What is the value of SP after the “sample loop” completes? $00F5 What is the value of SP after the “sum loop” completes? $00FF Did stack overflow occur? NO How could it have occurred? Push more than 191 items on the stack, the 192nd item would have overwritten RESULT Lecture #11 ECE 3430 – Intro to Microcomputer Systems Fall 2009


Download ppt "ECE 3430 – Intro to Microcomputer Systems"

Similar presentations


Ads by Google