Introduction to Embedded Systems EE319K (Gerstlauer), Spring 2013

Similar documents
Exam 1 Fun Times. EE319K Fall 2012 Exam 1A Modified Page 1. Date: October 5, Printed Name:

EE319K Exam 1 Summer 2014 Page 1. Exam 1. Date: July 9, Printed Name:

EE319K Spring 2015 Exam 1 Page 1. Exam 1. Date: Feb 26, 2015

EE319K Fall 2013 Exam 1B Modified Page 1. Exam 1. Date: October 3, 2013

Exam 1. Date: Oct 4, 2018

(2) Part a) Registers (e.g., R0, R1, themselves). other Registers do not exists at any address in the memory map

EE319K (Gerstlauer), Spring 2013, Midterm 1 1. Midterm 1. Date: February 21, 2013

EE319K Spring 2016 Exam 1 Solution Page 1. Exam 1. Date: Feb 25, UT EID: Solution Professor (circle): Janapa Reddi, Tiwari, Valvano, Yerraballi

Introduction to C. Write a main() function that swaps the contents of two integer variables x and y.

Exam 1. Date: February 23, 2018

Exam 1. EE319K Spring 2013 Exam 1 (Practice 1) Page 1. Date: February 21, 2013; 9:30-10:45am. Printed Name:

ARM Instruction Set Architecture. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Exam 1. Date: February 23, 2016

ARM Assembly Language. Programming

Exam 1. Date: March 1, 2019

Exam 1. Date: February 23, 2018

Cortex M3 Programming

EE319K Fall 2017 Final Exam UT EID: Page 1. Final Exam. Date: December 15, 2017

EE319K Spring 2016 Final Exam UT EID: Page 1. Final Exam. Date: May 13th 2016

Exam 1. Date: March 1, 2019

Final Exam. EE319K Fall 2018 Final Exam UT EID: Page 1. Date: December 19, Circle one: MT, NT, JV, RY, Printed Name:

ECE 471 Embedded Systems Lecture 5

CprE 288 Introduction to Embedded Systems Course Review for Exam 3. Instructors: Dr. Phillip Jones

ARM Cortex M3 Instruction Set Architecture. Gary J. Minden March 29, 2016

EE319K Spring 2012 Final Exam Version B LM3S1968 version Page 1 of 12

EE319K Fall 2017 Final Exam Solution Page 1. Final Exam. Date: December 15, 2017

ECE 498 Linux Assembly Language Lecture 5

Final Exam. Date: May 8, Circle one: VJR, NT, RY. Printed Name:

Processor Status Register(PSR)

A block of memory (FlashROM) starts at address 0x and it is 256 KB long. What is the last address in the block?

The ARM Cortex-M0 Processor Architecture Part-2

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

Final Exam Solutions

Real-Time Systems / Real-Time Operating Systems EE445M/EE380L.6, Spring 2015

CprE 288 Introduction to Embedded Systems ARM Assembly Programming: Translating C Control Statements and Function Calls

ECE 571 Advanced Microprocessor-Based Design Lecture 3

ARM Cortex-M4 Programming Model Memory Addressing Instructions

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

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design

ARM Assembly Programming

NET3001. Advanced Assembly

Control Flow Instructions

Final Exam. Date: December 11, 2014

EE319K Spring 2016 Final Exam UT EID: Page 1. Final Exam. Date: May 13th 2016

Chapter 2 Instructions Sets. Hsung-Pin Chang Department of Computer Science National ChungHsing University

ARM Cortex-A9 ARM v7-a. A programmer s perspective Part 2

Number Representations

ARM Cortex-M4 Programming Model Logical and Shift Instructions

ARM Assembly Language

ARM Cortex-M4 Programming Model Flow Control Instructions

Chapter 15. ARM Architecture, Programming and Development Tools

University of California, San Diego CSE 30 Computer Organization and Systems Programming Winter 2014 Midterm Dr. Diba Mirza

Lecture 4 (part 2): Data Transfer Instructions

Outline. ARM Introduction & Instruction Set Architecture. ARM History. ARM s visible registers

ECE251: Intro to Microprocessors Name: Solutions Mid Term Exam October 4, 2018

Chapter 2 Number System

Unsigned and signed integer numbers

Architecture. Digital Computer Design

CS341 *** TURN OFF ALL CELLPHONES *** Practice NAME

EE251: Tuesday September 5

Assembler: Basics. Alberto Bosio October 20, Univeristé de Montpellier

Bits and Bytes. Data Representation. A binary digit or bit has a value of either 0 or 1; these are the values we can store in hardware devices.

STEVEN R. BAGLEY ARM: PROCESSING DATA

Data Representation and Binary Arithmetic. Lecture 2

Do not start the test until instructed to do so!

Bitwise Instructions

LAB 1 Using Visual Emulator. Download the emulator Answer to questions (Q)

ARM Cortex-M4 Programming Model Arithmetic Instructions. References: Textbook Chapter 4, Chapter ARM Cortex-M Users Manual, Chapter 3

Hi Hsiao-Lung Chan, Ph.D. Dept Electrical Engineering Chang Gung University, Taiwan

ASSIGNMENT 5 TIPS AND TRICKS

Interrupt-Driven Input/Output

Chapter 2 Bits, Data Types, and Operations

EEM870 Embedded System and Experiment Lecture 4: ARM Instruction Sets

The ARM Instruction Set

Fundamentals of Programming (C)

Systems Architecture The ARM Processor

ARM-7 ADDRESSING MODES INSTRUCTION SET

Binary Numbers. The Basics. Base 10 Number. What is a Number? = Binary Number Example. Binary Number Example

ARM Instruction Set. Computer Organization and Assembly Languages Yung-Yu Chuang. with slides by Peng-Sheng Chen

n NOPn Unary no operation trap U aaa NOP Nonunary no operation trap i

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras

CMPSCI 201 Fall 2005 Midterm #2 Solution

Final Exam Solutions

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

MNEMONIC OPERATION ADDRESS / OPERAND MODES FLAGS SET WITH S suffix ADC

Chapter 2 Bits, Data Types, and Operations

Chapter 3: ARM Instruction Set [Architecture Version: ARMv4T]

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

ARM Instruction Set. Introduction. Memory system. ARM programmer model. The ARM processor is easy to program at the

Lab5 2-Nov-18, due 16-Nov-18 (2 weeks duration) Lab6 16-Nov-19, due 30-Nov-18 (2 weeks duration)

Writing ARM Assembly. Steven R. Bagley

Chapter 3. Information Representation

Introduction to Decision Structures. Boolean & If Statements. Different Types of Decisions. Boolean Logic. Relational Operators

ECE 471 Embedded Systems Lecture 6

CSE 30 Winter 2009 Final Exam

VE7104/INTRODUCTION TO EMBEDDED CONTROLLERS UNIT III ARM BASED MICROCONTROLLERS

Do not start the test until instructed to do so!

Comparison InstruCtions

EE445M/EE380L.6 Quiz 2 Spring 2017 Solution Page 1 of 5

Transcription:

The University of Texas at Austin Department of Electrical and Computer Engineering Introduction to Embedded Systems EE319K (Gerstlauer), Spring 2013 Midterm 1 Solutions Date: February 21, 2013 UT EID: Printed Last, First Your signature is your promise that you have not cheated and will not cheat on this exam, nor will you help others to cheat on this exam: Signature: Instructions: Closed book and closed notes. No calculators or any electronic devices (turn cell phones off). Please be sure that your answers to all questions (and all supporting work that is required) are contained in the space (boxes) provided. Anything outside the boxes will be ignored in grading. For all questions, unless otherwise stated, find the most efficient (time, resources) solution. Problem 1 10 Problem 2 10 Problem 3 15 Problem 4 20 Problem 5 30 Problem 6 15 Total 100

EE319K (Gerstlauer), Spring 2013, Midterm 1 Solutions 2 Problem 1 (10 points): Numbers (a) (5 points) How many bits are minimally needed to represent all days in a year? What C data type should be used to store such values? Number of Bits 9 bits C Data Type uint16_t or unsigned short (b) (5 points) What values has the 8-bit number 0x70 when converted to decimal and binary representations? Signed decimal Unsigned decimal Binary 7 * 16 = 112 7 * 16 = 112 %01110000 Problem 2 (10 points): Interfacing Interface a switch to (input) port PA7 of the LM3S1968 using negative logic. Assuming that no current can flow in or out of the LM3S1968 and that the switch is perfect (zero resistance when closed), what current will flow through the switch when it is closed? +3.3V LM3S1968 PA7 10kΩ I = V / R = 3.3V / 10kΩ = 0.33mA

EE319K (Gerstlauer), Spring 2013, Midterm 1 Solutions 3 Problem 3 (15 points): Arithmetic and Addressing (a) (5 points) For the following operation sequence, what will be the value of register R0 and condition code bits N, Z, V and C after execution of the sequence. Assume all values and registers are 8-bit wide: 8-bit sequence R0 N Z V C R1-111 R2 221 R0 R1 + R2 110 0 0 1 1 (b) (5 points) Consider the following operation sequence (in regular 32-bit ARM assembly): LDR R1,=-168 ASRS R2,R1,#2 CMP R1,R2 Mark which of the following branches will be taken after executing the above sequence: Branch Taken Not taken BEQ BHS BGE X X X BLO BLT X X (c) (5 points) Consider the following assembly program: AREA CODE ;assume this starts at address 0x0000.1000 num DCD 0x87654321 Start LDR R0,=num LDRSH R1,[R0] What is the value in register R1 at the end of execution? Big: 0xFFFF8765 Little: 0x00004321 (the ARM can be configured to different endianess and the result depends on that; default is little)

EE319K (Gerstlauer), Spring 2013, Midterm 1 Solutions 4 Problem 4 (20 points): Execution Given the following ARM assembly program: AREA DATA 0x20000000 00000000 res DCD 0 AREA CODE 0x000005D0 B500 f PUSH {LR 0x000005D2 2801 CMP R0,#0x01 0x000005D4 D007 BEQ done 0x000005D6 B401 PUSH {R0 0x000005D8 F1A00001 SUB R0, R0, #1 0x000005DC F7FFFFF8 BL f 0x000005E0 BC02 POP {R1 0x000005E2 FB00F001 MUL R0, R0, R1 0x000005E6 F85DEB04 done POP {LR 0x000005EA 4770 BX LR 0x000005EC F04F0002 Start MOV R0,#2 0x000005F0 F7FFFFEE BL f 0x000005F4 4900 LDR R1,=res 0x000005F6 6008 STR R0,[R1] (a) (10 points) Assume the stack pointer SP is initialized to 0x2001.0000. Show the contents of the stack and indicate the location of the stack pointer right after the point when the statement at address f has just been executed for the second time. 0x2000.FFEC 0x2000.FFF0 0x2000.FFF4 0x0000.05E1 SP 0x2000.FFF8 0x0000.0002 0x2000.FFFC 0x0000.05F5 (b) (5 points) What is the value in memory location res at the end of execution? 2 (c) (5 points) What general functionality does the subroutine f implement? Factorial (n!)

EE319K (Gerstlauer), Spring 2013, Midterm 1 Solutions 5 Problem 5 (30 points): Input/Output You are asked to develop a software module to control the seatbelt warning lamp as part of a car dashboard. For the part of the system that you are responsible for, the following inputs and outputs are relevant (all positive logic): Ports PB5 PB2 are connected to a RPM sensor that reports the current engine speed as a scaled (in units/increments of 500 RPM) unsigned 4-bit integer value, i.e. if the sensor reports a value of 2 on PB5 PB2, the engine speed is 1000 RPM. Port PB0 is connected to the seatbelt switch that indicates whether the seatbelt is fastened. Port PB7 is connected to the safety warning indicator LED. Your subsystem is supposed to turn on the LED if the engine is running (RPM >= 1000) and the seatbelt is not fastened. Since your code is part of a bigger system, make sure to develop subroutines that are friendly, i.e. that do not modify unrelated bits of ports. You can assume that relevant definitions are given: GPIO_PORTB_DATA_R GPIO_PORTB_DIR_R GPIO_PORTB_AFSEL_R GPIO_PORTB_DEN_R SYSCTL_RCGCGPIO_R SYSCTL_RCGCGPIO_GPIOB (= 0x00000002, port B clock gating control) (a) (10 points) Write the assembly code for the initialization subroutine of the Belt module. The Belt_Init subroutine should make PB7 an output, and PB0 and PB5 through PB2 inputs. Fill in the blanks in the code template below. You are not allowed to use bit-specific addressing or the BIC instruction. Belt_Init LDR R1, =SYSCTL_RCGCGPIO_R LDR R0, [R1] ORR_R0,R0,#SYSCTRL_RCGCGPIO_GPIOB STR R0, [R1] NOP NOP LDR R1, =GPIO_PORTB_DIR_R LDR R0, [R1] ORR R0,R0,#0x80 AND R0,R0,#0xC2 STR R0, [R1] LDR R1, =GPIO_PORTB_AFSEL_R LDR R0, [R1] AND R0,R0,#0x42 STR R0, [R1] LDR R1, =GPIO_PORTB_DEN_R LDR R0, [R1] ORR R0,R0,#0xBD STR R0, [R1] BX LR

EE319K (Gerstlauer), Spring 2013, Midterm 1 Solutions 6 (b) (20 points) Write a main C program that first calls the Belt_Init subroutine from (a) then performs a loop over and over to turn the LED on iff (if and only if) the engine is running (RPM >= 1000), and the seatbelt is not fastened. In all other cases, the LED should be off. // declaration of function implemented in assembly void Belt_Init(void); // main program void main(void) { Belt_Init(); while(1) { if((((gpio_portb_data_r & 0x3C) >> 2) >= 2) && ((GPIO_PORTB_DATA_R & 0x01) == 0)) { GPIO_PORTB_DATA_R = 0x80; else { GPIO_PORTB_DATA_R &= 0x7F; // alternate main program void main(void) { Belt_Init(); while(1) { if((((gpio_portb_data_r >> 2) && 0x0F) >= 2) && ((GPIO_PORTB_DATA_R & 0x01) == 0)) { GPIO_PORTB_DATA_R = 0x80; else { GPIO_PORTB_DATA_R &= 0x7F;

EE319K (Gerstlauer), Spring 2013, Midterm 1 Solutions 7 Problem 6 (15 points): C Programming and Parameter Passing Given below is the C code for a function that checks whether a number is prime. Translate the C code into assembly. Follow the AAPCS calling convention standard, i.e. use register R0 both to pass value v and return the result, and you can freely use registers R0 through R3. Note: in ARM assembly, the modulo operation (A % B) has to be implemented as (A (B * (A / B))). C code int32_t prime(int32_t v) { unsigned int32_t; for(i = 2; i < v; i++) { if((v % i) == 0) { return 0; return 1; Assembly code prime MOV R1,#2 loop CMP R1,R0 BLO done1 UDIV R2,R0,R1 MUL R2,R2,R1 CMP R0,R2 BEQ done0 ADD R1,R1,#1 B loop done0 MOV R0,#0 B done done1 MOV R0,#1 done BX LR

EE319K (Gerstlauer), Spring 2013, Midterm 1 Solutions 8 ASCII Table BITS 4 to 6 0 1 2 3 4 5 6 7 0 NUL DLE SP 0 @ P ` p B 1 SOH DC1! 1 A Q a q I 2 STX DC2 " 2 B R b r T 3 ETX DC3 # 3 C S c s S 4 EOT DC4 $ 4 D T d t 5 ENQ NAK % 5 E U e u 0 6 ACK SYN & 6 F V f v 7 BEL ETB ' 7 G W g w T 8 BS CAN ( 8 H X h x O 9 HT EM ) 9 I Y i y A LF SUB * : J Z j z 3 B VT ESC + ; K [ k { C FF FS, < L \ l ; D CR GS - = M ] m E SO RS. > N ^ n ~ F S1 US /? O o DEL

EE319K (Gerstlauer), Spring 2013, Midterm 1 9 Memory access instructions LDR Rd, [Rn] ; load 32-bit number at [Rn] to Rd LDR Rd, [Rn,#off] ; load 32-bit number at [Rn+off] to Rd LDR Rd, =value ; set Rd equal to any 32-bit value (PC rel) LDRH Rd, [Rn] ; load unsigned 16-bit at [Rn] to Rd LDRH Rd, [Rn,#off] ; load unsigned 16-bit at [Rn+off] to Rd LDRSH Rd, [Rn] ; load signed 16-bit at [Rn] to Rd LDRSH Rd, [Rn,#off] ; load signed 16-bit at [Rn+off] to Rd LDRB Rd, [Rn] ; load unsigned 8-bit at [Rn] to Rd LDRB Rd, [Rn,#off] ; load unsigned 8-bit at [Rn+off] to Rd LDRSB Rd, [Rn] ; load signed 8-bit at [Rn] to Rd LDRSB Rd, [Rn,#off] ; load signed 8-bit at [Rn+off] to Rd STR Rt, [Rn] ; store 32-bit Rt to [Rn] STR Rt, [Rn,#off] ; store 32-bit Rt to [Rn+off] STRH Rt, [Rn] ; store least sig. 16-bit Rt to [Rn] STRH Rt, [Rn,#off] ; store least sig. 16-bit Rt to [Rn+off] STRB Rt, [Rn] ; store least sig. 8-bit Rt to [Rn] STRB Rt, [Rn,#off] ; store least sig. 8-bit Rt to [Rn+off] PUSH {Rt ; push 32-bit Rt onto stack POP {Rd ; pop 32-bit number from stack into Rd ADR Rd, label ; set Rd equal to the address at label MOV{S Rd, <op2> ; set Rd equal to op2 MOV Rd, #im16 ; set Rd equal to im16, im16 is 0 to 65535 MVN{S Rd, <op2> ; set Rd equal to -op2 Branch instructions B label ; branch to label Always BEQ label ; branch if Z == 1 Equal BNE label ; branch if Z == 0 Not equal BCS label ; branch if C == 1 Higher or same, unsigned BHS label ; branch if C == 1 Higher or same, unsigned BCC label ; branch if C == 0 Lower, unsigned < BLO label ; branch if C == 0 Lower, unsigned < BMI label ; branch if N == 1 Negative BPL label ; branch if N == 0 Positive or zero BVS label ; branch if V == 1 Overflow BVC label ; branch if V == 0 No overflow BHI label ; branch if C==1 and Z==0 Higher, unsigned > BLS label ; branch if C==0 or Z==1 Lower or same, unsigned BGE label ; branch if N == V Greater than or equal, signed BLT label ; branch if N!= V Less than, signed < BGT label ; branch if Z==0 and N==V Greater than, signed > BLE label ; branch if Z==1 or N!=V Less than or equal,signed BX Rm ; branch indirect to location specified by Rm BL label ; branch to subroutine at label BLX Rm ; branch to subroutine indirect specified by Rm Interrupt instructions CPSIE I ; enable interrupts (I=0) CPSID I ; disable interrupts (I=1)

EE319K (Gerstlauer), Spring 2013, Midterm 1 10 Logical instructions AND{S {Rd, Rn, <op2> ; Rd=Rn&op2 (op2 is 32 bits) ORR{S {Rd, Rn, <op2> ; Rd=Rn op2 (op2 is 32 bits) EOR{S {Rd, Rn, <op2> ; Rd=Rn^op2 (op2 is 32 bits) BIC{S {Rd, Rn, <op2> ; Rd=Rn&(~op2) (op2 is 32 bits) ORN{S {Rd, Rn, <op2> ; Rd=Rn (~op2) (op2 is 32 bits) LSR{S Rd, Rm, Rs ; logical shift right Rd=Rm>>Rs (unsigned) LSR{S Rd, Rm, #n ; logical shift right Rd=Rm>>n (unsigned) ASR{S Rd, Rm, Rs ; arithmetic shift right Rd=Rm>>Rs (signed) ASR{S Rd, Rm, #n ; arithmetic shift right Rd=Rm>>n (signed) LSL{S Rd, Rm, Rs ; shift left Rd=Rm<<Rs (signed, unsigned) LSL{S Rd, Rm, #n ; shift left Rd=Rm<<n (signed, unsigned) Arithmetic instructions ADD{S {Rd, Rn, <op2> ; Rd = Rn + op2 ADD{S {Rd, Rn, #im12 ; Rd = Rn + im12, im12 is 0 to 4095 SUB{S {Rd, Rn, <op2> ; Rd = Rn - op2 SUB{S {Rd, Rn, #im12 ; Rd = Rn - im12, im12 is 0 to 4095 RSB{S {Rd, Rn, <op2> ; Rd = op2 - Rn RSB{S {Rd, Rn, #im12 ; Rd = im12 Rn CMP Rn, <op2> ; Rn op2 sets the NZVC bits CMN Rn, <op2> ; Rn - (-op2) sets the NZVC bits MUL{S {Rd, Rn, Rm ; Rd = Rn * Rm signed or unsigned MLA Rd, Rn, Rm, Ra ; Rd = Ra + Rn*Rm signed or unsigned MLS Rd, Rn, Rm, Ra ; Rd = Ra - Rn*Rm signed or unsigned UDIV {Rd, Rn, Rm ; Rd = Rn/Rm unsigned SDIV {Rd, Rn, Rm ; Rd = Rn/Rm signed Notes Ra Rd Rm Rn Rt represent 32-bit registers value any 32-bit value: signed, unsigned, or address {S if S is present, instruction will set condition codes #im12 any value from 0 to 4095 #im16 any value from 0 to 65535 {Rd, if Rd is present Rd is destination, otherwise Rn #n any value from 0 to 31 #off any value from -255 to 4095 label any address within the ROM of the microcontroller op2 the value generated by <op2> Examples of flexible operand <op2> creating the 32-bit number. E.g., Rd = Rn+op2 ADD Rd, Rn, Rm ; op2 = Rm ADD Rd, Rn, Rm, LSL #n ; op2 = Rm<<n Rm is signed, unsigned ADD Rd, Rn, Rm, LSR #n ; op2 = Rm>>n Rm is unsigned ADD Rd, Rn, Rm, ASR #n ; op2 = Rm>>n Rm is signed ADD Rd, Rn, #constant ; op2 = constant, where X and Y are hexadecimal digits: produced by shifting an 8-bit unsigned value left by any number of bits in the form 0x00XY00XY in the form 0xXY00XY00 in the form 0xXYXYXYXY

EE319K (Gerstlauer), Spring 2013, Midterm 1 11 General purpose registers Stack pointer Link register Program counter R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 (MSP) R14 (LR) R15 (PC) Condition code bits N negative Z zero V signed overflow C carry or unsigned overflow 256k Flash ROM 64k RAM I/O ports Internal I/O PPB 0x0000.0000 0x0003.FFFF 0x2000.0000 0x2000.FFFF 0x4000.0000 0x41FF.FFFF 0xE000.0000 0xE004.0FFF