“Assembly Table Lookup”

Slides:



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

Chapter 9 TRAP Routines and Subroutines. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9-2 Subroutines.
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
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.
S. Barua – CPSC 240 CHAPTER 9 TRAP ROUTINES AND SUBROUTINES The TRAP mechanism allows the user program.
CSS 372 Oct 2 nd - Lecture 2 Review of CSS 371: Simple Computer Architecture Chapter 3 – Connecting Computer Components with Buses Typical Bus Structure.
Midterm Wednesday 11/19 Overview: 25% First Midterm material - Number/character representation and conversion, number arithmetic - DeMorgan’s Law, Combinational.
ECE 265 – LECTURE 9 PROGRAM DESIGN 8/12/ ECE265.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#6)
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.
Objectives Implement pointers using indexed addressing modes Use pointers to access arrays, strings, structures, tables, and matrices Present finite-state.
Computer Science 210 Computer Organization Introduction to Subroutines.
Chapter 9 Chapter 9 Subroutines and TRAPs l Privileged Instructions l TRAP Routines l Subroutines.
Operating Systems Lecture November 2015© Copyright Virtual University of Pakistan 2 Agenda for Today Review of previous lecture Hardware (I/O, memory,
ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.
Chapter 9 TRAP Routines and Subroutines. 9-2 System Calls Certain operations require specialized knowledge and protection: specific knowledge of I/O device.
Assembly Language ELEC 330 Digital Systems Engineering Dr. Ron Hayne.
ECE 265 – LECTURE 11 Editing and the Assembler (updated 11/11/10) 12/15/ ECE265.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 3 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
5-1 EE 319K Introduction to Microcontrollers Lecture 5: Conditionals, Loops, Modular Programming, Sub- routines, Parameter passing.
User-Written Functions
Mon Sept. 11 Announcements
ECE 3430 – Intro to Microcomputer Systems
Chapter 9 TRAP Routines and Subroutines
MICROPROCESSOR BASED SYSTEM DESIGN
Buffered, Interrupt-Driven Printer Design Example
Computer Science 210 Computer Organization
ECE 3430 – Intro to Microcomputer Systems
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.
Control Structure Applications
Microprocessor Systems Design I
UNIT – Microcontroller.
ECE 3430 – Intro to Microcomputer Systems
Macros and Structured Programming
Additional Assembly Programming Concepts
Chapter 18 I/O in C.
CS 3305 System Calls Lecture 7.
Buffered, Interrupt-Driven Printer Design Example
ECE 3430 – Intro to Microcomputer Systems
Wed. Sept 6 Announcements
Chapter 9 TRAP Routines and Subroutines
Control Structure Applications
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
Chapter 9 TRAP Routines and Subroutines
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
TRAP Routines Subroutines Privileged Instructions
Chapter 9 TRAP Routines and Subroutines
Computer Science 210 Computer Organization
A Simple Two-Pass Assembler
Chapter 9 TRAP Routines and Subroutines
Operating Systems Lecture 3.
TRAP Routines Privileged Instructions Subroutines
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
Chapter 9 TRAP Routines and Subroutines
Computer Science 210 Computer Organization
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
Chapter 6 Programming the basic computer
COMP3221: Microprocessors and Embedded Systems
Chapter 9 TRAP Routines and Subroutines
Chapter 9 TRAP Routines and Subroutines
Accum A: Index X: CCR Bit Z: $0100 $0101 $0102 $0103 $0104 $0105
Chapter 9 TRAP Routines and Subroutines
Presentation transcript:

“Assembly Table Lookup” Module 1-E “Assembly Table Lookup” 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? “Assembly Table Lookup” 1 Pre-compute values, store in table. Lookup result when you need it. Can create more efficient code 2 Can use tables to jump program to different code locations

Lookup and interpolate Table Lookup Uses Jump Tables Non-Linear index // like a table of function pointers interrupt_handler* handlers[N]; // there are N potential interrupts, when interrupt 0 happens, // call code at first entry, etc… // Also useful for switch statements code* switch_cases[N]; // Like linear-index, except table has “holes” // Example: use BCD index to lookup days in month unsigned int days_in_month[] = {DCh, 31h, 28h, …}; Linear index Lookup and interpolate // Example: have some function. Don’t want to do // math for every value, instead pre-compute every value // store it in the table, lookup value at runtime // Example, y = x^3 + 10 unsigned int y_value[N] = {10, 13, 18, …}; // Table is incomplete, but has linear // characteristics between each data point. // Effectively, a piece-wise linear function // “Special” 9S12 instruction (TBL) does this // interpolation for you // ex: | _ _ // | / // |/_ _ _ // 0 4 8 unsigned int y_val[] = {0 /*x=0*/, 2/*x=4*/, 2/*x=8*/, …};

Jump Tables A jump table is a special form of lookup table that contains addresses of subroutines Note: Here, the table entries are “double-byte” (16-bits) in length, since they represent addresses in memory Applications: select (“vector to”) a specific interrupt service routine under hardware control select a function/subroutine to execute based on an input stream that has been parsed by a command interpreter

Jump Tables +0 +2 +4 (N-1)*2 puts desired return address on stack

Jump Tables note use of indirect addressing mode Less efficient, more straight-forward way: jsr [d,x] rts

Table Lookup - Linear Index

Table Lookup - Non-linear Index A non-linear index simply means that the index only takes on a subset of all possible values, i.e., there are don’t cares in the table Example: Packed BCD number used as a table lookup index, say for a calendar program (note that there is no “month 00”, nor are there months “0A” through “0F”) Question: In such an application, is it more efficient to use the “raw” BCD value as a table lookup index (thus “wasting” space in the table), or convert the BCD value to binary before using it as a lookup index (thus “saving” space in the table)? A “pair-o-docs”: Sometimes, in order to save space, you have to waste it!

Table Lookup - Non-linear Index wasted space

Table Lookup - Non-linear Index Note: Same code as “normal” case

Lookup and Interpolate (TBL) The “TBL” instruction can be used to perform a linear interpolation on values that fall between a pair of data entries stored in memory Example: Estimation of room temperature based on data read from an analog input channel interfaced to a silicon diode circuit Operation performed: (A)  (addr) + [ (B) X { (addr+1) – (addr) } ] where indexed addressing mode is used and (B) is interpreted as a binary fraction* *of form 0 . 2-1 2-2 2-3 2-4 ... (unsigned)

Lookup and Interpolate (TBL) Use of TBL instruction: set up index register to point to table entry “X1” (the table entry closest to, but less than or equal to, the desired lookup value) “X2” is the table entry that follows “X1”, and “XL” is the desired lookup point (between “X1” and “X2”) along the X-axis calculate (XL-X1)  (X2-X1) and place the resulting binary fraction in the B register (typically requires use of FDIV instruction) execute the TBL instruction; the result placed in the A register will be the interpolated result along the Y-axis: (A)  Y1 + [ (B) X (Y2 – Y1) ]

Lookup and Interpolate (TBL) TBL in action... Y Y2 YL Y1 X X1 XL X2

The (base 10) value that gets stored at location lookup is: A: 8 B: 10 E: none of the above The (base 10) value that gets stored at location lookup is: A: 8 B: 10  C: 16 D: 22 E: none of the above org $800 ldx #table ldab #$40 tbl 0,x staa lookup ldab #$C0 tbl 1,x staa lookup+1 halt bra halt table fcb 8 fcb 16 fcb 24 lookup rmb 2 B = 10

The (base 10) value that gets stored at location lookup+1 is: A: 8 org $800 ldx #table ldab #$40 tbl 0,x staa lookup ldab #$C0 tbl 1,x staa lookup+1 halt bra halt table fcb 8 fcb 16 fcb 24 lookup rmb 2 The (base 10) value that gets stored at location lookup+1 is: A: 8 B: 10 C: 16 D: 22 E: none of the above The (base 10) value that gets stored at location lookup+1 is: A: 8 B: 10 C: 16 D: 22  E: none of the above D = 22

Example Application Write an interactive "stupid quote" generator that prompts the user for a single character identifier (here, "a" through "f") and prints the corresponding quote on the emulated terminal screen. If the character entered is "out of range", an error message should be printed. If the character q is entered, the program should terminate. The user interface should function as follows (user input is in bold): Welcome to the Stupid Quote Generator What do you want to say today (a-f)? a Your own favorite quote #1 What do you want to say today (a-f)? d Your own favorite quote #4 What do you want to say today (a-f)? g Message index is out of range What do you want to say today (a-f)? 2 What do you want to say today (a-f)? q Nice talking to you...

Example Application This program consists of three modular components: a main program that implements the user interface. a pmsgx subroutine that prints the string pointed to by X at entry and terminates when an ASCII null character is encountered. a lookup subroutine that is passed the message index (in the range of 0 to N-1) in the A register and returns the starting address of the desired message string in the X register. In addition, two I/O library routines are provided: inchar — inputs an ASCII character from the terminal keyboard and returns it in the A register outchar — prints the ASCII character passed to it in the A register on the terminal screen

; ; Stupid Quote Generator main ldx #welcome jsr pmsgx ; print welcome message mprompt ldx #prompt jsr pmsgx ; print prompt jsr inchar jsr outchar ; input and echo response cmpa #'q' beq mexit ; exit if 'q' entered suba #'a' ; subtract off bias of ASCII 'a' ; range should now be 0 to 5 (for a-f) bmi nok ; *not* OK if negative cmpa #N ; check to see if within range blt rok nok ldx #nogood jsr pmsgx ; if not within range, print error message bra mprompt ; and try again

rok jsr lookup ; if within range, perform message lookup jsr pmsgx ; and print desired string bra mprompt ; go back for more mexit ldx #bye jsr pmsgx ; program termination sloop bra sloop ; sit in infinite loop/wait for reset ; ; Message printing subroutine ; Prints message string pointed to by X register pmsgx ldaa 1,x+ cmpa #NULL beq pexit jsr outchar bra pmsgx pexit rts

; ; Lookup subroutine ; Index of message (range: 0 to N-1) passed in A register ; Pointer to desired message string returned in X register lookup asla ldx #qtable ldx a,x rts qtable fdb quote1 fdb quote2 fdb quote3 fdb quote4 fdb quote5 fdb quote6

; Message declarations N equ 6 ; number of valid messages NULL equ 0 ; ASCII null character (string termination) RET equ $d ; ASCII return character LF equ $a ; ASCII line feed character welcome fcb RET,LF fcc "Welcome to the Stupid Quote Generator" fcb RET,LF,NULL prompt fcc "What do you want to say today (a-f)? " fcb NULL nogood fcb RET,LF fcc "Message index is out of range" bye fcb RET,LF fcc "Nice talking to you..."

quote1 fcb RET,LF fcc "Your own favorite quote #1" fcb RET,LF,NULL quote2 fcb RET,LF fcc "Your own favorite quote #2" quote3 fcb RET,LF fcc "Your own favorite quote #3" quote4 fcb RET,LF fcc "Your own favorite quote #4" quote5 fcb RET,LF fcc "Your own favorite quote #5" quote6 fcb RET,LF fcc "Your own favorite quote #6"