ECE 3430 – Intro to Microcomputer Systems

Slides:



Advertisements
Similar presentations
Ch. 7 Local Variables and Parameter Passing From the text by Valvano: Introduction to Embedded Systems: Interfacing to the Freescale 9S12.
Advertisements

EET 2261 Unit 6 The Stack; Subroutines
Microprocessors.
Programming 68HC11.
EET 2261 Unit 5 Tables; Decision Trees & Logic Instructions
Revised: Aug 1, EE4390 Microprocessors Lesson 6,7 Instruction Set, Branch Instructions, Assembler Directives.
HCS12 Arithmetic Lecture HC12 Arithmetic Addition and Subtraction Shift and Rotate Instructions Multiplication Division.
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell 68HC12 Arithmetic Chapter 3.
Microcontroller Fundamentals & Programming
ECE 265 – LECTURE 7 The M68HC11 Basic Instruction Set Logical, Shift and Rotate, Data Testing 8/14/ ECE265.
Rabel Talpur:12BME#025.  40-pin chip  Developed by Motorola in 1975  16 address lines and 8 data lines  Used only +5V.
© 2010 Kettering University, All rights reserved..
The M68HC11 Basic Instruction Set Basic Arithmetic Instructions
Chapter 2: 68HC11 Assembly Programming
H. Huang Transparency No.2-1 The 68HC11 Microcontroller Chapter 2: 68HC11 Assembly Programming The 68HC11 Microcontroller.
Assembly Programming on the TI-89 Created By: Adrian Anderson Trevor Swanson.
© 2010 Kettering University, All rights reserved..
EECC250 - Shaaban #1 Lec # 20 Winter Microcontroller Basics A microcontroller is a small, low-cost computer-on-a-chip which usually includes:
Stacks and Subroutines. Some example stacks Stacks and subroutine usage The stack is a special area of the random access memory in the overall memory.
ECE 265 – LECTURE 8 The M68HC11 Basic Instruction Set The remaining instructions 10/20/ ECE265.
Physics 413 Chapter 4 A Fork in the Road LDAB # $ 13 here :ADDA # $ 24 DEC B BNE here WAI BNE is the new instruction. Branch if not equal to zero.
ECE 447: Lecture 12 Logic, Arithmetic, Data Test and Control Instructions of MC68HC11.
ECE 265 – LECTURE 5 The M68HC11 Basic Instruction Set 12/8/ ECE265.
1 Stacks, Subroutines, I/O Routines Today: First Hour: Stacks, Subroutines –Section 3.9,3.10 of Huang’s Textbook –In-class Activity #1 Second Hour: I/O.
1 ECE 372 – Microcontroller Design Assembly Programming HCS12 Assembly Programming Addressing Modes Stack Operations Subroutines.
1 Introduction to Microcontroller Microcontroller Fundamentals & Programming.
ECE Lecture 21 Typical Assembly Language Program Bugs.
Microcontroller Fundamentals & Programming Arithmetic Instructions.
Advanced Assembly Language Programming
© 2010 Kettering University, All rights reserved..
ECE 447: Lecture 11 Introduction to Programming in Assembly Language.
Embedded Systems Lecture 5 January 25 th, 2016.
Subroutines and Stacks. Stack The stack is a special area in memory used by the CPU to store register information or general data information during program.
Physics 413 Chapter 4: Advanced Assembly Programming.
1 Subroutines Advanced Programming. 2 Top-Down approach to problem solving Algorithm step by step description of how to solve a problem Divide and Conquer.
1 Stack Advanced Programming. 2 The Stack It is a special area of memory used as temporary storage A stack is a LIFO data structure Putting data into.
Stacks and Subroutines May 23. Stacks and subroutine usage The stack is a special area of the random access memory in the overall memory system The stack.
CPEN 231: Microcomputer Architecture and Assembly Programming Lecture 10: Stack and Subroutines John Tadrous, Ph.D. ECE Rice University
EET 2261 Unit 6 The Stack; Subroutines
The 68HC11 Microcontroller Minnesota State University, Mankato
ECE 3430 – Intro to Microcomputer Systems
Addressing Modes in Microprocessors
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
HC11 Programming.
ECE 3430 – Intro to Microcomputer Systems
Classification of Instruction Set of 8051
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
Microcomputer Programming
Principles of Computers 14th Lecture
Arithmetic and Logic Chapter 5
68000 Arithmetic Instructions
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME4447/6405 Microprocessor Control of Manufacturing Systems and
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
Chapter 8 Central Processing Unit
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ECE 3430 – Intro to Microcomputer Systems
Arithmetic and Logic Chapter 5
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
8051 ASSEMBLY LANGUAGE PROGRAMMING
ECE 447: Lecture 15 Stack Operations.
EET 2261 Unit 6 The Stack; Subroutines
Indexing Through Memory
Presentation transcript:

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

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 $E000 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

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

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

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

ECE 3430 – Intro to Microcomputer Systems More Instructions Example What are the contents of ACCA after each instruction? LDAA #%1011 0110 ACCA Carry ASRA %1101 1011 0 LSRA %0110 1101 1 RORA %1011 0110 1 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 = 0 RORA ‡ ‡ ‡ ‡ ‡ = set to one or cleared to zero depending on run-time circumstances Lecture #11 ECE 3430 – Intro to Microcomputer Systems Fall 2009

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 #%11110000 NEGA  A = %00010000 COMA  A = %11101111 Lecture #11 ECE 3430 – Intro to Microcomputer Systems Fall 2009

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

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

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

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

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 10 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

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

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