Mon Sept. 11 Announcements

Slides:



Advertisements
Similar presentations
1 System Calls (TRAPS) and Subroutines Patt and Patel Ch. 9.
Advertisements

Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
68HC11 Polling and Interrupts
CSS 372 Lecture 1 Course Overview: CSS 372 Web page Syllabus Lab Ettiquette Lab Report Format Review of CSS 371: Simple Computer Architecture Traps Interrupts.
Recap – Our First Computer WR System Bus 8 ALU Carry output A B S C OUT F 8 8 To registers’ input/output and clock inputs Sequence of control signal combinations.
Chapter 4 H1 Assembly Language: Part 2. Direct instruction Contains the absolute address of the memory location it accesses. ld instruction:
Midterm Wednesday 11/19 Overview: 25% First Midterm material - Number/character representation and conversion, number arithmetic - DeMorgan’s Law, Combinational.
Lab 1 – Assembly Language and Interfacing Start date: Week 3 Due date: Week 4 1.
P.1ECE 331, Prof. A. Mason Professor Andrew Mason Michigan State University Spring 2013 ECE 331: PC Lab 1: Using HC12 ASM Simulators.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
ECE 265 – LECTURE 8 The M68HC11 Basic Instruction Set The remaining instructions 10/20/ ECE265.
Interrupts and reset operations. Overview  Introduction to interrupts – What are they – How are they used  68HC11 interrupt mechanisms – Types of interrupts.
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.
Objective At the conclusion of this chapter you will be able to:
6-1 EE 319K Introduction to Microcontrollers Lecture 6: Indexed Addressing Mode and Variants, Functional Debugging, Arrays, Strings.
ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.
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.
8-1 EE 319K Introduction to Microcontrollers Lecture 8:Fixed Point Numbers, Local Variables, Binding, Allocation, Access, Deallocation.
ECE Lecture 21 Typical Assembly Language Program Bugs.
Advanced Assembly Language Programming
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
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.
Revised: Aug 1, EE4390 Microprocessors Lessons 11, 12 Advanced Assembly Programming.
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.
5-1 EE 319K Introduction to Microcontrollers Lecture 5: Conditionals, Loops, Modular Programming, Sub- routines, Parameter passing.
EET 2261 Unit 6 The Stack; Subroutines
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
PROGRAMMING THE BASIC COMPUTER
ECE 3430 – Intro to Microcomputer Systems
Chapter 9 TRAP Routines and Subroutines
MIPS Instruction Set Advantages
Buffered, Interrupt-Driven Printer Design Example
Computer Science 210 Computer Organization
Learning Outcome #1 Architecture and Programming Model
Mon. Oct 2 Announcements Quiz Postponed to Wednesday – still only on 2.a + 2.b Video lecture for 2.a posted Lab 6 experiment extension You must come to.
ECE 3430 – Intro to Microcomputer Systems
Control Structure Applications
PROGRAMMING THE BASIC COMPUTER
Macros and Structured Programming
ECE 3430 – Intro to Microcomputer Systems
Buffered, Interrupt-Driven Printer Design Example
Wed. Sept 6 Announcements
“Assembly Table Lookup”
Chapter 9 TRAP Routines and Subroutines
Chapter 10 The Stack.
Branching and Looping Lecture L3.2.
Control Structure Applications
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME4447/6405 Microprocessor Control of Manufacturing Systems and
Graded Quiz #3 Sept. 15, 2017 Clicker [AB]
Chapter 9 TRAP Routines and Subroutines
Computer Science 210 Computer Organization
The University of Adelaide, School of Computer Science
Chapter 9 TRAP Routines and Subroutines
Chapter 9 TRAP Routines and Subroutines
TRAP Routines Privileged Instructions Subroutines
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
Chapter 9 TRAP Routines and Subroutines
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ECE 447: Lecture 15 Stack Operations.
EET 2261 Unit 6 The Stack; Subroutines
Chapter 9 TRAP Routines and Subroutines
Chapter 9 TRAP Routines and Subroutines
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ECE511: Digital System & Microprocessor
Lecture 3 - Instruction Set - Al
Presentation transcript:

Mon Sept. 11 Announcements Lab should be open 24/7 starting tomorrow Lab/HW 4 will be posted tomorrow Code submission will be done on BB this year. Please submit Lab 2 code ASAP – Lab 3 (and future labs) are due by the end of the day for your lab period.

Assembly Parameter Passing Module 1-F Assembly Parameter Passing Tim Rogers 2017

Learning Outcome #1 Architecture and Programming Model “An ability to program a microcontroller to perform various tasks” Architecture and Programming Model Instruction Set Overview Assembly Control Structures Control Structure Applications Table Lookup Parameter Passing Macros and Structured Programming How?

Objective Why? Ultimately, they all turn into assembly “Assembly Parameter Passing” Why? Almost any language you can name implements function calls Passing parameters to functions is universal N equ ? org $800 macme pshb ; (2) pshx ; (2) pshy ; (2) ldx #XA ; (2) ldy #YA ; (2) movw #0,ACM ; (5) movw #0,ACM+2 ; (5) ldab #N ; (1) loop emacs ACM ; (13) leax 2,x ; (2) leay 2,y ; (2) dbne b,loop ; (3) puly ; (3) pulx ; (3) pulb ; (3) rts ; (5) ACM rmb 4 XA fdb ?,?,? YA fdb ?,?,? Ultimately, they all turn into assembly

4 Basic Methods Call by value (aka via registers) Fastest Call by value (aka via registers) Call by name (aka via pointers to global memory) Embed Parameters following the “call” Via the stack Weirdest Most General

Method 1: Call by Value (Registers) Easiest to use used # parameters is small Input: (A) = <packed BCD number> bcdb Output: Unchanged = converted binary Example: Convert packed BCD to binary

Method 1: Call by Value (Registers) Example calling code ldaa #99 jsr bcdb ; use b for something

Method 2: Call by Name (Global Area) Uses a CPU index register as a pointer to the beginning of a global parameter area Where used: pass a character string pass a data structure (e.g., an array) Input: (X) = <pointer to start of array> sortem Output: (X) Unchanged Array in memory sorted Example: Sort an array in memory

Method 2: Call by Name (Global Area) Global Memory Example calling code ldx #AA jsr sotem ; use AA for something

Method 3: Following “Call” Instruction Use the “return address” as the pointer to the data. Effectively get a private parameter area Function MUST correct the return address before RTS Example: Print a string Input: ( ((SP)):((SP)+1) ) = <first byte of input string> pmsg Output: ((SP)):((SP)+1) = <correct return addr> Recall: JSR puts the address after the JSR instruction on the stack

Method 3: Following “Call” Instruction desired return address return address placed on stack points here

Method 4: Using the Stack The system stack is the technique most commonly used by high-level language compilers While this method has a significant amount of “overhead” associated with it (in terms of the complexity of the calling and exit sequences), it makes possible two important features associated with modern high-level languages: recursion (the ability of a subroutine to call itself) reentrancy (the ability of a code module to be shared among quasi-simultaneously executing tasks) Basically means you can take an interrupt, call the function in the interrupt and everything works

Method 4: Using the Stack Input: (SP)+2 = <pointer to data structure> epadds Output: (SP) = <pointer to return data structure> Example: Extended precision binary add

Method 4: Using the Stack Note: Here, data is stored in high order byte first format (also referred to as “big endian”)

Method 4: Using the Stack

Method 4: Using the Stack

Wed Sept. 13 Announcements In-Class Quiz Friday Sept 15 Covers everything between last quiz and where we get today

A detailed example of each method Convert packed-BCD to binary Call by value (aka via registers) Call by name (aka via pointers to global memory) Embed Parameters following the “call” Via the stack

Method 1: Call by Value (Registers) Example Input in (A) Output to (B) conv binary = (10 x u.n.) + l.n. “BAB”  (B)  (A) + (B)

A detailed example of each method Call by value (aka via registers) Call by name (aka via pointers to global memory) Embed Parameters following the “call” Via the stack Sort array

Array Sorting Example Method: “Bubble Sort” use pairwise comparison and exchange use X register to point to AA[i] use Y register to point to AA[i+1]

Global Memory X initialize X and Y pointers Note: B  J

A detailed example of each method Call by value (aka via registers) Call by name (aka via pointers to global memory) Embed Parameters following the “call” Via the stack Print Message

Method 3: Following “Call” Instruction

A detailed example of each method Call by value (aka via registers) Call by name (aka via pointers to global memory) Embed Parameters following the “call” Via the stack Extended Precision Add

Method 4: Using the Stack

Stack State at Entry to “epadds” SP 

Stack State at Entry to “epadds” MSB augend MSB addend #N #N #N SP 

Stack State at Entry to “epadds” LSB augend LSB addend ••• MSB augend MSB addend #N SP  #N

Stack State at Entry to “epadds” LSB augend LSB addend ••• MSB augend MSB addend #N SP  #N

Stack State at Entry to “epadds” MSB return addr LSB return addr N LSB augend LSB addend ••• MSB augend MSB addend SP  #N #N

Stack State as “epadds” Runs MSB return addr LSB return addr N LSB augend LSB addend ••• MSB augend MSB addend SP  X  X*  *after post-increment by 1

Stack State as “epadds” Runs MSB return addr LSB return addr N LSB augend LSB addend ••• MSB augend MSB addend SP  X 

Stack State as “epadds” Runs MSB return addr LSB return addr N LSB result LSB addend ••• MSB augend MSB addend SP  X  X**  **after post-increment by 2

Stack State Just Before “epadds” Returns MSB return addr LSB return addr N LSB result LSB addend ••• MSB result MSB addend SP  X  X**  **after post-increment by 2

Exit Sequence Following Return From “epadds” MSB return addr LSB return addr N LSB result LSB addend ••• MSB result MSB addend SP  SP*  *after post-increment by 1

Exit Sequence Following Return From “epadds” MSB return addr LSB return addr N LSB result LSB addend ••• MSB result MSB addend SP  SP**  **after post-increment by 2

Exit Sequence Following Return From “epadds” MSB return addr LSB return addr N LSB result LSB addend ••• MSB result MSB addend SP  SP**  **after post-increment by 2

Exit Sequence Following Return From “epadds” MSB return addr LSB return addr N LSB result LSB addend ••• MSB result MSB addend SP  SP** 

Exit Sequence Following Return From “epadds” MSB return addr LSB return addr N LSB result LSB addend ••• MSB result MSB addend SP 

Interrupts: Basics Special return from interrupt instruction Normally, CPU executes your program. PC is controlled by your program. N equ ? org $800 main pshb ; (2) pshx ; (2) pshy ; (2) ldx #XA ; (2) ldy #YA ; (2) movw #0,ACM ; (5) movw #0,ACM+2 ; (5) ldab #N ; (1) loop emacs ACM ; (13) leax 2,x ; (2) leay 2,y ; (2) dbne b,loop ; (3) puly ; (3) pulx ; (3) pulb ; (3) rts ; (5) ACM rmb 4 XA fdb ?,?,? YA fdb ?,?,? interrupt_handler ; does some interrupt stuff rti When done, comes back to your program BUT, you can actually get interrupted at ANY time! Examples of interrupts: Sensor firing, timer going off, etc…

Interrupts: Basics Like RTS, except does a bunch of extra stuff. Why all the extra stuff?? Because you have no idea where in the program you will be when an interrupt happens. Need to save ALL register state! RTI puts all this state back. Description Assembly mnemonic operation Examples Return from interrupt RTI (CCR)  ((SP)), (SP)  (SP) + 1, (D)  ((SP)), (SP)  (SP) + 2, (X)  ((SP)), (SP)  (SP) + 2, (Y)  ((SP)), (SP)  (SP) + 2, (PC)  ((SP)), (SP)  (SP) + 2 Interrupt happens: ”stack registers” automatically RTI called: ”unstack registers” automatically

Reentrancy, interrupts and function calling Is there a problem?: A: Yes B: No Is there a problem?: A: Yes  B: No What is a problem?: A: (X) modified B: (Y) modified C: (B) modified D: (ACM) modified  E: (XA) modified What is a problem?: A: (X) modified B: (Y) modified C: (B) modified D: (ACM) modified E: (XA) modified Reentrancy, interrupts and function calling A function (subroutine) is reentrant if it can be interrupted at any time and then called from the interrupt. N equ ? org $800 macme pshb ; (2) pshx ; (2) pshy ; (2) ldx #XA ; (2) ldy #YA ; (2) movw #0,ACM ; (5) movw #0,ACM+2 ; (5) ldab #N ; (1) loop emacs ACM ; (13) leax 2,x ; (2) leay 2,y ; (2) dbne b,loop ; (3) puly ; (3) pulx ; (3) pulb ; (3) rts ; (5) ACM rmb 4 XA fdb ?,?,? YA fdb ?,?,? interrupt_handler ; does some interrupt stuff jsr macme ; does some other stuff rti To be safe, the bottom line is: To be reentrant – do not read/write from global memory Output written to global memory

Other “software interrupt” instructions Description Assembly mnemonic operation Examples Unimplemented op code TRAP (CCR)  ((SP)), (SP)  (SP) + 1, (D)  ((SP)), (SP)  (SP) + 2, (X)  ((SP)), (SP)  (SP) + 2, (Y)  ((SP)), (SP)  (SP) + 2, (PC)  ((SP)), (SP)  (SP) + 2 I bit of CCR  1 (PC)  (Trap Vector) Software Interrupt SWI (PC)  (SWI Vector) Also called “exceptions”. Exceptions = SW triggered Interrupts = HW triggered

Example Application Write a program that prompts a user for a five-digit access code (or “PIN”), checks it against a valid combination stored in memory, prompts the user to enter the code a second time if an error is made, and denies access if the PIN is entered incorrectly the second time. For security, the digits of the PIN should be echoed to the screen as “*” characters. Three possible scenarios are outlined below: Welcome to the MegaMoney ATM! Enter PIN: ***** Access granted Error in PIN – try again… Sorry – access denied Your money is our money until you can figure out how to withdraw it!! 1 valid code – first try invalid code – first try 2 valid code – second try invalid code – first try 3 invalid code – second try

STEP 1: Write a subroutine checkp that compares the 5-digit PIN entered by the user against a 5-digit PIN stored in memory. At entry to checkp, the PIN entered by the user is pushed onto the stack (in the order that it was entered), as five separate bytes each containing a single BCD digit (i.e., it is in “unpacked” format). Also at entry to checkp, the X register points to the valid 5-digit code stored in memory; it, too, is stored in “unpacked” format, in five consecutive bytes. At exit, checkp should return with the carry flag set (C=1) if the two combinations match, or with the carry flag clear (C=0) if the two combinations do not match. Also at exit, the combination tested should be removed from the stack and the X register should be restored to its original value (no other registers need to saved/restored).

checkp ; ; Subroutine checkp compares the 5-digit code stored in memory ; (pointed to by X) with the 5-digit code passed on the stack ; If the two codes match, checkp returns with C=1; else, C=0 ; The 5-byte code passed to this routine is de-allocated before exit ; The X register retains its original value puly ; save return address in Y ldab #NDIGS ; B used as loop counter and decb ; as pointer offset ; Comparison loop checkl pula ; get digit of combination entered cmpa b,x ; compare with valid code bne checkb ; if mismatch, know combo is bad decb bpl checkl ; B ranges from 4 to 0 ; If "fall through", all digits match sec ; return with CF = 1 pshy ; restore return address saved in Y rts ; note that X is unchanged ; If "mismatch" occurs, de-allocate remainder of combination ; that was passed on the stack and return with CF = 0 checkb leas b,sp ; de-allocate rest of combination clc ; return with CF = 0

STEP 2: Write a main program that prints a welcome message, prompts the user to enter a PIN, checks the PIN using the checkp routine, gives the user a second chance if necessary, checks the second PIN entered using checkp, and prints a sarcastic message if the user fails to enter a valid PIN the second time. The main program should also provide storage for the valid 5-digit combination (of your choice). The main program should simply terminate with a STOP instruction after the “access granted” or “access denied” message is printed.

; ATM access code verifier ; Tests 5-digit code entered by user ; and compares it with 5-digit code ; stored in memory CR equ $0d LF equ $0a NULL equ 0 NDIGS equ 5 ; number of digits in combination NTRYS equ 2 ; number of trys allowed ; Start of main program ; 1. Welcome user ; 2. Prompt for PIN ; 3. Input 5-digit PIN (echo "*" as code entered) ; 4. Call checkp to see if PIN is valid ; 5. If PIN is not valid then ; if this is the second try then ; print "access denied" and exit ; else ; print "try again" and goto 2 ; endif ; else print "access granted" and exit ; endif

movb #NTRYS,ntry ; initialize number of trys jsr pmsg fcb CR,LF org $800 main movb #NTRYS,ntry ; initialize number of trys jsr pmsg fcb CR,LF fcc "Welcome to the MegaMoney ATM" fcb CR,LF,NULL prompt fcc "Enter your 5-digit PIN: ",NULL ldab #NDIGS pmptlp jsr inchar ; get character jsr atoh ; convert ASCII to HEX psha ; place on stack ldaa #'*' jsr outchar ; echo * dbne b,pmptlp ldx #combo ; X points to valid combination jsr checkp lbcs wasgood dec ntry beq goaway ; give user another chance ; if still has any trys left ; else, deny access to user fcc "Error in PIN - try again" bra prompt

fcc "Sorry - Access Denied" ; Uh oh...user ran out of chances goaway jsr pmsg fcb CR,LF fcc "Sorry - Access Denied" fcc "Your Money is Our Money Until You Can Figure Out Your PIN!" fcb CR,LF,NULL stop wasgood fcc "Access granted" jmp main ; start over ; Combination declaration combo fcb 7,6,5,9,4 ntry rmb 1 ; number of trys