Coe538 Final Study Guide 2016 (Questions & Answers)

Similar documents
Programming the Motorola MC68HC11 Microcontroller

538 Lecture Notes Week 5

538 Lecture Notes Week 5

COE538 Lecture Notes Week 3 (Week of Sept 17, 2012)

538 Lecture Notes Week 3

Using the stack and the stack pointer

Lecture 9 Subroutines

Table 1: Mnemonics Operations Dictionary. Add Accumulators Add B to Y. Add with carry to B. Add Memory to B. Add 16-bit to D And B with Memory

CodeWarrior. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

ECE 367 -Experiment #1 Fall 2012

The Motorola 68HC11 Instruc5on Set

538 Lecture Notes Week 2

Sample Problem Set #1

Introduction to Mechatronics. Fall Instructor: Professor Charles Ume. Interrupts and Resets

Chapter 2: HCS12 Assembly Programming. EE383: Introduction to Embedded Systems University of Kentucky. Samir Rawashdeh

C SC 230 Computer Architecture and Assembly Language April 2000 Exam Sample Solutions

CMPEN 472 Sample EXAM II

ME4447/6405. Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics. Instructor: Professor Charles Ume LECTURE 7

MC9S12 Assembler Directives A Summary of MC9S12 Instructions Disassembly of MC9S12 op codes. Summary of HCS12 addressing modes ADDRESSING MODES

EE 308 Spring A software delay

1. Memory Mapped Systems 2. Adding Unsigned Numbers

Exam I Review February 2017

Exam 2 E2-1 Fall Name: Exam 2

; export symbols ; export 'Entry' symbol. ; include derivative specific macros PORTA EQU $0000 PORTB EQU $0001 DDRA EQU $0002 DDRB EQU $0003

COSC345 Software Engineering. Basic Computer Architecture and The Stack

ECE331 Handout 3- ASM Instructions, Address Modes and Directives

EE319K Final Fall 2005 Solution C. (3) Question 1. (3) Question 2. short function(const short in){ return in+5; } const

68HC11 Opera,ng Modes

; export symbols XDEF Entry ; export 'Entry' symbol ABSENTRY Entry ; for assembly entry point

538 Lecture Notes Week 3

Lecture 6 Assembly Programming: Branch & Iteration

Exam 2 E2-1 Fall Name: Exam 2

CHAPTER 8. Solutions for Exercises

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-470/570: Microprocessor-Based System Design Fall 2014.

Outline. 2.8 Stack. 2.9 Subroutines

Timing Generation and Measurements

It translates (converts) assembly language to machine code.

Exam 1 Feb. 23, 25, 27?

BRANCH IF REGISTER IS HIGHER/GREATHER/ THAN OPERAND e.g. CMPA #$D0

Lab 7: Asynchronous Serial I/O

Cross Assembly and Program Development

HC11 Instruction Set

EE 5340/7340 Motorola 68HC11 Microcontroler Lecture 1. Carlos E. Davila, Electrical Engineering Dept. Southern Methodist University

Microcontrollers. 2IN60: Real-time Architectures (for automotive systems) Mike Holenderski,

Ryerson University Department of Electrical and Computer Engineering ELE 538 Microprocessor Systems Final Examination December 8, 2003

EE319 K Lecture 7. Address mode review Assembler, Debugging Psuedo ops 16 bit timer finite state machines. University of Texas ECE

Introduction to Microcontrollers III

2) [ 2 marks] Both of the following statements cause the value $0300 to be stored in location $1000, but at different times. Explain the difference.

Introduction to Programming the 9S12 in C Huang Sections 5.2 and 5.3. You will be able to use all of the Motorola data manuals on the exam.

2. Arithmetic Instructions addition, subtraction, multiplication, divison (HCS12 Core Users Guide, Sections 4.3.4, and ).

EE 3170 Microcontroller Applications

Lecture #4 Microcontroller Instruction Set Embedded System Engineering Philip Koopman Monday, 25-Jan-2016

Quick Guide to Using Code Warrior

Lecture 7 Assembly Programming: Shift & Logical

0b) [2] Can you name 2 people form technical support services (stockroom)?

AN Kbyte Addressing with the M68HC11. Overview

Introduction to Microcontrollers III

Module 1-D. Control Structure Applications. Tim Rogers 2017 [1.D]-1

EE 308 Spring A software delay. To enter a software delay, put in a nested loop, just like in assembly.

SECTION 6 CENTRAL PROCESSING UNIT

EE319 K Lecture 3. Introduction to the 9S12 Lab 1 Discussion Using the TExaS simulator. University of Texas ECE

Reading Assignment. 68HC12 Instruction Set. M68HC12 Instruction Set Categories. Some Tips. Endianness (Byte Order) Load and Store Instructions

ECE 372 Microcontroller Design Basic Assembly Programming. ECE 372 Microcontroller Design Basic Assembly Programming

ECE 3120 Computer Systems Arithmetic Programming

UNIVERSITY OF MANITOBA DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING. Term Test #2 Solution ECE 3610 MICROPROCESSING SYSTEMS

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

HC11 Instruction Set Architecture

HC11 Instruction Set Architecture

Module 1-G. Marcos and Structured Programming

Programming Book for 6809 Microprocessor Kit

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

Chapter 2 HCS12 Assembly Language

Lecture 20: Interrupt Devices

Chapter 4: Advanced Assembly Programming. EE383: Introduction to Embedded Systems University of Kentucky. Samir Rawashdeh

CET335 Microprocessor Interfacing Lab 5: LCD Interface (Bus Attached Peripheral)

Introduction to Embedded Microcomputer Systems Lecture 10.1

m 1 se 7 m 23 Introduction to Embedded Microcomputer Systems Lecture 16.1 Recap Finite State Machines Pointer implementation

ECE 3120: Computer Systems Chapter 8: ECE-3120-A Musical

ECE 331: PC Lab 3 Stack and Subroutines

Motorola HC11. Fun with Microcontrollers and Embedded Systems

Wed. Sept 6 Announcements

Module 2.F. Buffered, Interrupt-Driven Printer Design Example. Tim Rogers 2017

ECE372 CodeWarrior Simulator Andreou/Michaelides

Introduction to the MC9S12 Hardware Subsystems

AN1064. Motorola Semiconductor Application Note. Use of Stack Simplifies M68HC11 Programming By Gordon Doughman. Introduction

N bit is set if result of operation in negative (MSB = 1) Z bit is set if result of operation is zero (All bits = 0)

Addressing Mode Description Addressing Mode Source Format Abbrev. Description

538 Lecture Notes Week 1

A Simple MC9S12 Program

ECE/CE 3720: Embedded System Design

Lecture 5 Assembly Programming: Arithmetic

Interrupts. Interrupts Resets Low Power Modes. Resets Low Power Modes

Introduction to Microcontrollers

ECE 3610 MICROPROCESSING SYSTEMS

EB301. Motorola Semiconductor Engineering Bulletin. Programming EEPROM on the MC68HC811E2 during Program Execution. Freescale Semiconductor, I

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Introduction. ECE/CS 5780/6780: Embedded System Design. Golden Rule of Software Development. Software Maintenance. Assembly Language Style Issues

Lecture #13 Interrupts Embedded System Engineering Philip Koopman Monday, 29-Feb-2016

CS/ECE 5780/6780: Embedded System Design

Transcription:

Coe538 Study Guide 1 of 8 Coe538 Final Study Guide 2016 (Questions & Answers) This version contains questions AND answers. This study guide is meant to help you review coe538 and prepare for the final. How to use this study guide. The Guide has 2 versions: one with answers; another without. Start with the version without answers. Each question indicates how many minutes should be needed to answer it. Read a question. If you think you need The questions WITH ANSWERS 1. (10 minutes) Write an assembly language fragment that will make the contents of address 3 contain the value 5. a) Do this with 2 assembly languages instructions and determine the number of clock cycles required and the total size (in bytes) of the program fragment. b) Do this with a single assembly instruction. How many clock cycles? How many bytes? a) ldaa #5 ;machine language: 86 05 (2 bytes) (1 clock cycle) staa 3 ;machine language: 7a 00 03 (3 bytes) (3 clock cycles) ; TOTAL: Size: 5 bytes; Clock cycles: 4 b) movb #5,3 ;Machine language: 18 0b 05 00 03 (5 bytes, 4 clock cycles) REMARKS: If you assemble this code with Codewarrior, it will use Direct addressing instead of Extended addressing for memory locations in page zero (0-0xff). This will make the instructions 1 byte shorted. However, we do not use the Direct addressing mode in this course. The only addressing modes you need to know are: PC-relative Indexed (including pre/post increment/decrement) Extended Immediate Indexed Indirect

Coe538 Study Guide 2 of 8 2. (10 minutes) Write an assembly language fragment that will make the contents of address 3 contain the value stored in address 5. (Use as many instructions as you wish. Calculate the running time and size of the assembly language fragment.) ldab 5 ;machine language: f6 00 05 (3 bytes) (3 clock cycle) stab 3 ;machine language: 7b 00 03 (3 bytes) (3 clock cycles) ; TOTAL: Size: 6 bytes; Clock cycles: 6 ;You could, of course, use Acc A or a single movb instruction. 3. (5 minutes) Write a C language fragment that makes the contents of address 0x0003 be 5. *(char *) 3 = 5; 4. (5 minutes) Write a C language fragment that makes the contents of address 0x0003 the same as the contents of address 0x0005. *(char *) 3 = *(char *)5; 5. (8 minutes) Write assembly language such that the 2 most significant bits of AccA are set to 1, the next 2 bits are set to 0 and the 4 least significant bits are inverted. (For example, if AccA contains 10100101, it would become 11001010.) ora #$f0 eora #$3f ;It could also be done as follows (less efficiently) ora #$c0 anda #$cf eora #$0f 6. (5 minutes) Repeat the previous question in C assuming the byte you wish to modify is a variable called p. p = (p 0xf0) ^ 0x3f; //It could also be written as: p = (p & 0x0f) ^ 0xcf;

Coe538 Study Guide 3 of 8 7. Write a Timer module to generate an interrupt every millisecond. The total number of milliseconds should be maintained in a global variable called time that maintains a 4-digit count of milliseconds elapsed in packed bcd format. (Use output compare channel 2.) Your code should have an inittimer subroutine that initializes the timer and a TimerISR interrupt service routine. Assume that the interrupt vector is at 0xffea. Assume that a 10 MHz clock drives the timer module. Assume the module base is 0x0040. ROMStart EQU $4000 ; absolute address to place my code/constant data TIOS equ $40 ;Timer Input Capture/Output Compare Select TCTRL1 equ $46 ;Timer Control Register 1 TCNT equ $44 ;16-bit main Timer counter TIE equ $4C ;Timer Interrupt Enable Register TFLG1 equ $4E ;Timer Flag Register 1 TC2 equ $54 ;Output Compare Register Channel 2 ORG $400 time ds.b 2 ;4-digit bcd counter ; code section ORG ROMStart Entry: _Startup: lds #$800 ; initialize the stack pointer ;initialize "time" (2 bytes) to zero clr time clr time+1 jsr inittimer cli ; enable interrupts bra * ;inifinte loop inittimer: ;Configure Channel 2 as Output Compare

Coe538 Study Guide 4 of 8 ldaa #%100 staa TIOS ;Turn on the Timer module ldaa #$80 staa TCTRL1 ;Enable Channel 2 interrupts ldaa #4 staa TIE ;Set OutputCompare2 to TCNT+10000 ldd TCNT addd #10000 std TC2 rts TimerISR: ;Clear Flag ldaa #4 staa TFLG1 ;Set OutputCompare2 10000 cyles later ldd TC2 addd #10000 std TC2 ;increment bcd counter (time) ldaa time+1 adda #1 daa staa time+1 ldaa time adca #0 daa staa time rti ;************************************************************** ;* Interrupt Vectors * ;************************************************************** org $ffea dc.w TimerISR ORG $FFFE DC.W Entry ; Reset Vector

Coe538 Study Guide 5 of 8 8. (25 minutes) A function counts the number of times a given character appears in a nullterminated string. For example, the string "qwartaay" contains the character 'a' 3 times. The function could be described in C as follows: unsigned char char_count_in_string(char * str, char ch) { unsigned char count = 0; while(*str) { if(*(str++) == ch) { count++; } } return count; } The documentation for an assembly language subroutine to perform this function follows. Complete the code. ;Subroutine: CountCharInString ;Description: Counts the instances of the character specified ; in Acc A that occurs in the null-terminated string ; whose starting address is specified by register X. ;Parmameters: ; AccA: the character to count ; X: Starting address of null terminated string to search. ;Returns: ; The number of matching characters as an unsigned number ; in Acc. B. ;Side Effects: ; All registers (except for CCR and B) have the same ; values when the subroutine returns. CountCharInString: clrb ;count mainained in AccB, initialed to 0 pshx ;save X so it can be restored continue cmpa 0,x ; bne notin incb notin tst 1,x+ bne continue ;nul char (end of string) reached?

Coe538 Study Guide 6 of 8 pulx rts 9. Translate the C function to assembler using the standard parameter passing conventions used by the C compiler. (Assume that the result is returned in AccB.) ;Subroutine: CountCharInString ;Description: Counts the instances of the character specified ; as parameter on stack (offset +7) ; whose starting address is specified by ; parameter on stack (offset +5). ;Parmameters: ; ch: the character to count (7,sp) ; astring: Starting address of null terminated ; string to search. (5,sp) ;Returns: ; The number of matching characters as an unsigned number ; in Acc. B. ;Side Effects: ; All registers (except for CCR & B) have the same values ; when the subroutine returns. CountCharInString: ch equ 7 ;offset in Stack to ch parameter astring equ 5 ;offset in Stack to astring parameter pshx psha clrb ldx astring,sp ldaa ch,sp continue cmpa 0,x bne notin incb notin tst 1,x+ bne continue pula pulx rts 10. How can you add Accumulator A to Accumulator D? Write the instruction(s). (Assume unsigned integers in both A and D.) ;One possible way

Coe538 Study Guide 7 of 8 staa tmp +1 ;tmp is a global 16-bit (2 byte) variable clr tmp addd tmp ;tmp now contains a 2-byte integer with msbyte zero and lsbyte = AccA 11. Translate the C function to assembler using the standard parameter passing conventions used by the C compiler. (Assume that the result is returned in AccB.) ;Subroutine: CountCharInString ;Description: Counts the instances of the character specified ; as parameter on stack (offset +7) ; whose starting address is specified by ; parameter on stack (offset +5). ;Parmameters: ; ch: the character to count (7,sp) ; astring: Starting address of null terminated ; string to search. (5,sp) ;Returns: ; The number of matching characters as an unsigned number ; in Acc. B. ;Side Effects: ; All registers (except for CCR and B) have the same values ; when the subroutine returns. CountCharInString: pshx psha clrb ldx 5,sp ldaa 7,sp continue cmpa 0,x bne notin incb notin tst 1,x+ bne continue pula pulx rts 9. Consider the 3 common methods of serial communication: SCI, SPI and I²C. Suppose two

Coe538 Study Guide 8 of 8 devices are connected for bi-directional communicaation using each of these protocols. Apart from ground and power, how many wires connect the two devices using each of the protocols? Rank the protocols from fastest to slowest. Which protocols (if any) allow bidirectional communication between more than 2 devices using a single bus? SCI: 2 wires (Tx and Rx); SPI: 3 wires (MISO, MOSI, SS); IIC: 2 wires (SCK, SDA) Fastest: SPI; Medium: IIC; Slowest: SCI Only SPI and IIC (which are bus protocols). SCI can only ben used between 2 devices: a DCE and DTE) 1. Determine the machine language and the number of clock cycles needed to execute each of the instructions below: ldaa #6 ldaa $1234 ldaa 0,x 4023 8606 ldaa #6 ;1 cycle 4025 B612 34 ldaa $1234 ;3 cycles 4028 A600 ldaa 0,x ;3 cycles