Review Activity 1 CALL and RET commands in assembler

Similar documents
Using peripherals on the MSP430 (if time)

Lecture test next week

Why embedded systems?

ECE2049 Homework #2 The MSP430 Architecture & Basic Digital IO (DUE Friday 9/8/17 at 4 pm in class)

ECE2049: Embedded Computing in Engineering Design A Term Fall Lecture #8: Making it work: LEDs, Buttons & Keypad

PHYS 319. Things to do before next week's lab Whirlwind tour of the MSP430 CPU and its assembly language Activity 1.

Integer Representation

ECE2049-E18 Lecture 6 Notes 1. ECE2049: Embedded Computing in Engineering Design E Term Lecture #6: Exam Review

Before next weeks lab:

ECE2049: Embedded Computing in Engineering Design C Term Spring Lecture #7: More Digital IO

ECE2049-E17 Lecture 6 1. ECE2049: Embedded Computing in Engineering Design E Term Lecture #6: Exam Review

Before Class Install SDCC Instructions in Installing_SiLabs-SDCC- Drivers document. Solutions to Number Systems Worksheet. Announcements.

ECE2049: Embedded Computing in Engineering Design A Term Fall Lecture #9: Exam Review w/ Solutions

Expressions. Eric McCreath

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)

CONTENTS: Program 1 in C:

9 Using Equation Networks

Goals for this Week. CSC 2400: Computer Systems. Bits, Bytes and Data Types. Binary number system. Finite representations of binary integers

ECE2049 E17 Lecture 4 MSP430 Architecture & Intro to Digital I/O

ECGR 4101/5101, Fall 2016: Lab 1 First Embedded Systems Project Learning Objectives:

Data III & Integers I

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

SISTEMI EMBEDDED. The C Pre-processor Fixed-size integer types Bit Manipulation. Federico Baronti Last version:

Embedded Systems - FS 2018

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

ECE2049: Embedded Computing in Engineering Design C Term Spring Lecture #3: Of Integers and Endians (pt. 2)

CS 253. January 14, 2017

Chapter 3. Computer Science & Engineering 155E Computer Science I: Systems Engineering Focus. Existing Information.

Data III & Integers I

LAB A Translating Data to Binary

Fixed-Point Math and Other Optimizations

CS107, Lecture 3 Bits and Bytes; Bitwise Operators

CpSc 111 Lab 3 Integer Variables, Mathematical Operations, & Redirection

Data III & Integers I

Getting Started with the Texas Instruments ez430

Computer Science & Engineering 150A Problem Solving Using Computers

SISTEMI EMBEDDED. The C Pre-processor Fixed-size integer types Bit Manipulation. Federico Baronti Last version:

Arithmetic Operations

Embedded Systems - FS 2018

Computer Science & Engineering 150A Problem Solving Using Computers. Chapter 3. Existing Information. Notes. Notes. Notes. Lecture 03 - Functions

ECE2049 E17 Lecture 2: Data Representations & C Programming Basics

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

Interrupts, Low Power Modes

Chapter 4: Basic C Operators

CS 24: INTRODUCTION TO. Spring 2015 Lecture 2 COMPUTING SYSTEMS

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection

Today's plan: Announcements General Strategy Microcontroller programming concepts/last bits of assembly Activity 2

C++ Programming Lecture 11 Functions Part I

Lecture 5: MSP430 Interrupt

CS 64 Week 1 Lecture 1. Kyle Dewey

6-1 (Function). (Function) !*+!"#!, Function Description Example. natural logarithm of x (base e) rounds x to smallest integer not less than x

Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2 Fall 2018

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

CS 31: Intro to Systems Binary Arithmetic. Martin Gagné Swarthmore College January 24, 2016

CS 261 Fall Mike Lam, Professor Integer Encodings

Integers II. CSE 351 Autumn 2018

CSI31 Lecture 5. Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial

9/23/15. Agenda. Goals of this Lecture. For Your Amusement. Number Systems and Number Representation. The Binary Number System

ME 172. Lecture 2. Data Types and Modifier 3/7/2011. variables scanf() printf() Basic data types are. Modifiers. char int float double

Variables and Operators 2/20/01 Lecture #

6. General purpose Input/Output

Few reminders and demos

A flow chart is a graphical or symbolic representation of a process.

ME 461 C review Session Fall 2009 S. Keres

Physics 319 Spring 2015: Introduction to the Programming and Use of Microprocessors

C and Programming Basics

Princeton University Computer Science 217: Introduction to Programming Systems. Goals of this Lecture. Number Systems and Number Representation

Course Outline Introduction to C-Programming

SISTEMI EMBEDDED. The C Pre-processor Fixed-size integer types Bit Manipulation. Federico Baronti Last version:

Computer Organization and Levels of Abstraction

Numerical computing. How computers store real numbers and the problems that result

Arithmetic for Computers

Variables and literals

Fundamentals of Programming Session 2

Arduino Uno. Power & Interface. Arduino Part 1. Introductory Medical Device Prototyping. Digital I/O Pins. Reset Button. USB Interface.

Week 2: Console I/O and Operators Arithmetic Operators. Integer Division. Arithmetic Operators. Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.

SIGNED AND UNSIGNED SYSTEMS

CHW 469 : Embedded Systems

Computational Applications in Nuclear Astrophysics using Java Java course Lecture 2

Number Systems and Number Representation

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

CS107, Lecture 2 Bits and Bytes; Integer Representations

Introduction to Programming

Special Topics for Embedded Programming

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

CS 31: Introduction to Computer Systems. 03: Binary Arithmetic January 29

CPU: SOFTWARE ARCHITECTURE INSTRUCTION SET (PART

CPE/EE 323 Introduction to Embedded Computer Systems Homework III

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

MIDTERM#1. 2-(3pts) What is the difference between Von Neumann & Harvard processor architectures?

Recap from Last Time. CSE 2021: Computer Organization. It s All about Numbers! 5/12/2011. Text Pictures Video clips Audio

CS 107 Lecture 2: Bits and Bytes (continued)

This simulated machine consists of four registers that will be represented in your software with four global variables.

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

CS107, Lecture 3 Bits and Bytes; Bitwise Operators

Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2

Chapter 3: Operators, Expressions and Type Conversion

Representation of Information

Transcription:

Today's Plan: Announcements Review Activity 1 CALL and RET commands in assembler Lecture test Programming in C continue

Announcements: Projects: should be starting to think about. You will need to provide a short written description (eg 1/2 page) of what you plan to assemble/build, and what parts you will require. Bring ideas to the lab next week! Submit 1/2 page in the lab Feb 5-9. Project Scope: Your project must use the MSP430 as a central component. Your project should incorporate at least one non-trivial external hardware component (sensor, motor, display etc). Your project may (but is not required) to communicate with a host computer for display or user interaction. Parts: We have access to many electronic components, some mechano and many motors and sensors that you may borrow for your project. Who pays for parts that need to be acquired will depend on what the parts are, who gets to keep them, and their price.

Activity 1 Write commands which will configure all pins of port 1 as inputs, and move the value from port 1 to register R7. Write the binary number which will be in the 16 bit register R7 after these operations assuming that the pins of port 1 were connected to 3V. Port P1 registers: P1REN P1SEL P1DIR P1OUT P1IN ; Port P1 resistor enable ; Port P1 selection ; Port P1 direction ; Port P1 output ; Port P1 input

Activity 1 Write commands which will configure all pins of port 1 as inputs, and move the value from port 1 to register R7. Write the binary number which will be in the 16 bit register R7 after these operations assuming that the pins of port 1 were connected to 3V. mov.b 0x00, &P1DIR mov.b &P1IN, R7 R7 = 0xXXFF mov.b used so as to write to only P1DIR and not to P1DIR and whatever is next in memory (P1IFG). mov.b used to copy only P1IN, and not also whatever is next in memory (P2OUT). unknown?

Program Flow Calling Subroutines Move.b #00001111,... mov.w #60000, r9 CALL #Delay... Delay: dec r9 jnz Delay RET

Programming in C Data types: char, unsigned char 8 bit integer short, unsigned short (usually 16 bit integer, size on msp430?) int, unsigned int usually an integer of the native word size 16 bits long, unsigned long 32 bit integer long long, unsigned long long 64 bit integer float floating point number (32 bits) (floating point operations are very expensive on a proces like the msp430 that lacks a dedicated fpu).

Programming in C Libraries: there are some standard libraries available that extend the operations you can easily use. eg: the math library gives access to functions like: sin(x), cos(x), tan(x), ln(x), log(x) etc... To use math functions, you need to: #include <math.h> at the top of the file, and also to put: -lm on the compilation command line Other libraries provide routines for string manipulations, timing, etc...

Programming in C #include <msp430.h> volatile unsigned int i=0; int main(void) { WDTCTL = WDTPW + WDTHOLD; P1DIR = 0x41; } for(;;){ } for ( i = 0 ; i < 20000 ; i++ ){ if ( i == 0 ) P1OUT ^= 0x01; if ( i == 6000) P1OUT ^= 0x40; }

Programming in C Operators: =, +, -, *, / % - modulus & - bitwise AND - bitwise OR ^ - bitwise XOR ~ - bitwise NOT << - bitshift left >> - bitshift right Force a bit on: a = 2 Force a bit off: a &= ~2 Flip a bit: a ^= 2; See Jean-Francois talk about these bitwise operators here: https://www.youtube.com/watch?v=kwcjclunlug Comparison: ==, <, >,!= if (i < 3), if (i!= 3) && - logical AND if (i == 1 && j == 2) - logical OR if (i == 1 j == 2 )! logical NOT What about sin, cos, sqrt, etc? These are not built in to the C language. However...

Programming in C Libraries: there are some standard libraries available that extend the operations you can easily use. eg: the math library gives access to functions like: sin(x), cos(x), tan(x), sqrt(x), ln(x), log(x) etc... To use math functions, you need to: #include <math.h> at the top of the file, and also put: -lm on the compilation command line. Other libraries provide routines for string manipulations and other things... These libraries tend to take up a substantial amount of flash and consume (precious) ram. You should try to avoid these on the MSP430 if at all possible!

Programming in C int multiply_together(int x, int y) { return x*y; You can define other functions that can } take arguments and return values.... y = multiply_together(4,8);... The function definition either needs to come in the file before you call it, or you need to supply a function prototype before you call it. A prototype for this function would simply be: int multiply_together(int x, int y);

Data types: char, unsigned char 8 bit integer ( -128 to 127 or 0 to 255) short, unsigned short (usually 16 bit integer, size on msp430?) int, unsigned int usually an integer of the native word size: 16 bits (-32768 to 32767 or 0 to 65536) long, unsigned long 32 bit integer (~ -2x10 9 to ~2x10 9 or 0 to ~4x10 9 ) long long, unsigned long long 64 bit integer (~ -9x10 18 to ~ 9 x 10 18 or 0 to ~2 x 10 19 ) float floating point number (32 bits) (floating point operations are very expensive on a processor like the msp430 that lacks a dedicated fpu - avoid if possible).

Data Types: In many compilers, can use types: uint8_t/ int8_t (same as unsigned char/char) uint16_t/int16_t (same as unsigned int/int on msp430) uint32_t/int32_t (same as unsigned long/long on msp430) uint64_t/int64_t These are 'better' because you always know exactly how big they are. To use these, add #include <stdint.h> at the top of the file.

Binary Numbers, signed vs unsigned On the msp430, a word is 16 bits. So a C 'int' is 16 bits. 16 bits can hold 65536 different values: An unsigned int represents values between 0 -> 65536 Binary numbers are usually represented using the two's complement: representation An int represents values between -32768 -> 32767 For a 3 bit number: Unsigned signed 000 0 0 001 1 1 010 2 2 011 3 3 100 4-4 101 5-3 110 6-2 111 7-1 Why? Addition and subtraction work very nicely: eg take 2 3. We know 2 3 should be -1. To accomplish 2-3, take 2 + (-3), ie 010 + 101 = 111 = -1.

Binary Numbers, signed vs unsigned If you are interpreting a number as a signed value: a 1 in the MSB indicates a negative value. To multiply a number by -1: a) Invert all the bits b) add 1 to the result: Eg: 3 = 011 -> 100 + 1 = 101 = -3 To go back: 101 -> 010 +1 = 011 = 3 When writing the hexadecimal value of a variable, you almost never see negatives. ie: (char) -1 would often be expressed as: 0xFF

Indentation. Please use proper indentation of your C code to make it readable! Tabs of 3-4 spaces are generally best. There are tools that can help. Many text editors can help you indent properly. For Mac: install indent using macports. See http://www.cprogramming.com/tutorial/style.html for more details than you care about, see: http://en.wikipedia.org/wiki/indent_style