ECE2049 HW #1-- C programming and Binary Number Representations (DUE 9/1/2017 At the BEGINNING of class)

Similar documents
ECE2049 HW #1-- C programming and Binary Number Representations (DUE 1/19/2018 At the BEGINNING of class)

ECE2049 HW #1-- C programming and Binary Number Representations (DUE Friday 8/31/2018 At the BEGINNING of class)

ECE2049: Homework 1. Consider the following code to compute the average of your exam grades: #define NUM_EXAMS (3)

ECE2049: Homework 1. Due: Thursday, 25 May 2017 by 7pm

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

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 #9: Exam Review w/ Solutions

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

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

ECE2049: Embedded Systems in Engineering Design Lab Exercise #3 C Term Making a Time and Temperature Display

Reading: Davies , 8.3-4, , MSP430x55xx User's Guide Ch. 5,17, MSP430F5529 Launchpad User's Guide

ECE2049 E17 Lecture 2: Data Representations & C Programming Basics

Computer Systems Programming. Practice Midterm. Name:

ECE2049 Embedded Computing in Engineering Design. Lab #0 Introduction to the MSP430F5529 Launchpad-based Lab Board and Code Composer Studio

Thus needs to be a consistent method of representing negative numbers in binary computer arithmetic operations.

Byte Ordering. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

SIGNED AND UNSIGNED SYSTEMS

2. MACHINE REPRESENTATION OF TYPICAL ARITHMETIC DATA FORMATS (NATURAL AND INTEGER NUMBERS).

SISTEMI EMBEDDED. Basic Concepts about Computers. Federico Baronti Last version:

Byte Ordering. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CS16 Exam #1 7/17/ Minutes 100 Points total

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

LING 388: Computers and Language. Lecture 5

Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring:

World Inside a Computer is Binary

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

Reading: Davies , 8.3-4, , MSP430x55xx User's Guide Ch. 5,17

CSC201, SECTION 002, Fall 2000: Homework Assignment #2

UNIT 7A Data Representation: Numbers and Text. Digital Data

17. Instruction Sets: Characteristics and Functions

ECE2049 Homework #4 Analog-to-Digital Conversion and the ADC12 (Due Thursday 2/15/2018 to box outside AK-011 by 9 am)

COMP2611: Computer Organization. Data Representation

Introduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C

l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

M1 Computers and Data

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

COMP2121: Microprocessors and Interfacing. Number Systems

CpSc 1111 Lab 4 Formatting and Flow Control

Integers II. CSE 351 Autumn 2018

CS-211 Fall 2017 Test 1 Version A Oct. 2, Name:

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

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name: ID:

Few reminders and demos

(Refer Slide Time: 00:23)

Time (self-scheduled): Location Schedule Your Exam: What to bring:

Arithmetic and Bitwise Operations on Binary Data

Do not start the test until instructed to do so!

Page 1. Where Have We Been? Chapter 2 Representing and Manipulating Information. Why Don t Computers Use Base 10?

The type of all data used in a C++ program must be specified

Representation of Information

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

Binary Representations and Arithmetic

Copy: IF THE PROGRAM or OUTPUT is Copied, then both will have grade zero.

N.B. These pastpapers may rely on the knowledge gained from the previous chapters.

Introduction to Computers and Programming. Numeric Values

EE 109 Unit 3. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

ECE2029: Introduction to Digital Circuit Design Lab 3 Implementing a 4-bit Four Function ALU

Integers II. CSE 351 Autumn Instructor: Justin Hsia

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Why Don t Computers Use Base 10? Lecture 2 Bits and Bytes. Binary Representations. Byte-Oriented Memory Organization. Base 10 Number Representation

1/29/2018. Starting a Program Executes its main Function. ECE 220: Computer Systems & Programming. The Function main Divides into Two Parts

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

Lab 03 - x86-64: atoi

15110 PRINCIPLES OF COMPUTING SAMPLE EXAM 2

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #04

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

As stated earlier, the declaration

Question 4: a. We want to store a binary encoding of the 150 original Pokemon. How many bits do we need to use?

QUIZ: What value is stored in a after this

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

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

Hardware: Logical View

Bits and Bytes January 13, 2005

Why Don t Computers Use Base 10? Lecture 2 Bits and Bytes. Binary Representations. Byte-Oriented Memory Organization. Base 10 Number Representation

CS367 Test 1 Review Guide

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls

EE 109 Unit 2. Binary Representation Systems

CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting

HW2: MIPS ISA Profs. Daniel A. Menasce, Yutao Zhong, and Duane King Fall 2017 Department of Computer Science George Mason University

CS61c Midterm Review (fa06) Number representation and Floating points From your friendly reader

EE 109 Unit 2. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

Chapter 2 Bits, Data Types, and Operations

CIS192 Python Programming. Robert Rand. August 27, 2015

Do not turn the page until 5:10.

Week 3 Lecture 2. Types Constants and Variables

CS107, Lecture 3 Bits and Bytes; Bitwise Operators

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

The type of all data used in a C (or C++) program must be specified

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

Bits and Bytes. Why bits? Representing information as bits Binary/Hexadecimal Byte representations» numbers» characters and strings» Instructions

Lab 1 Implementing a Simon Says Game

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

CpSc 1011 Lab 4 Formatting and Flow Control Windchill Temps

Integers II. CSE 351 Autumn Instructor: Justin Hsia

: Principles of Imperative Computation Victor Adamchik. Practice Exam - I

Lab 1 Implementing a Simon Says Game

Exam 1 Practice CSE 232 Summer 2018 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

Lesson 7. Reading and Writing a.k.a. Input and Output

Course overview. Computer Organization and Assembly Languages Yung-Yu Chuang 2006/09/18. with slides by Kip Irvine

Transcription:

ECE2049 HW #1-- C programming and Binary Number Representations (DUE 9/1/2017 At the BEGINNING of class) Your homework should be neat and professional looking. You will loose points if your HW is not properly submitted (by properly I mean legible and stapled with a cover sheet including your ECE box number). Any code must be typed to be graded. Please, no papers with ripped or ruffly edges! Always review lecture notes and reading assignments before attempting the homework Show all of your work. No work = No points! Clearly indicate results. Always write neatly. The grader can not be expected to GUESS what you meant to do! Reading -- Davies Ch 1&2, class notes, see Useful Links Problem #1 (25 pts) a) How many times would each of the following loops actually iterate on the MSP430F5529? Explain your reasoning. (10 pts) a) How many times would each loop actually iterate on the MSP430F5529? Explain your reasoning. (10 pts) unsigned char kk; unsigned int inval, out, mm=1, cnt=65535; kk = 1; while (kk > 0) /* do a few things */ /* */ kk++; >> What is the value of kk in the last 3 loops? while (cnt) // equivalent to while (cnt!= 0) inval = (mm + cnt)/cnt; out = myfunction(inval); mm *= 2; cnt = cnt >> 1; What are the values of cnt, mm and inval at the end of the first loop and at the end of the final loop?

b) Rewrite this code segment using a for loop and a switch case statement instead of the while loop and if statements. Note: The function is NOT one from our demo lab. (5 pts) unsigned char trial = 0, tp_history[100];... while (trial < 100) tp = alphatouchpad(); // returns letter A-E for touch pad tp_history[trial] = tp; if (tp == 'A') led_on(0); else if (tp == 'B') led_on(1); else if (tp == 'C') led_on(2); else if (tp == 'D') led_on(3); else if (tp == 'E') led_on(4); trial++; c) In the real world, the data collected from a sensor like a pressure sensor or a temperature sensor or a microphone are often noisy. That is, a single reading is often not reliable. Often the readings over time will be smoothed or averaged usually using a moving averager. Assume we have an array of raw data points. To form an array of M- point moving averages we start with the M-th point in the array and form the average of the of the previous M points then mover over one point in the raw data and forms the average of those previous M points, etc. If r[n] = raw data m[n]= 1 M n r[i] = moving average i=n M +1 Write a complete C program that does the following. In main(), declare 2 arrays, one for the raw data and one for the moving averages, and fill the raw data array with 200 random integers with values between -500 and 2000 exclusive (Hint: In this case you may use the C library function rand() random number generator to help generate the data). Use a compiler directive to define M as a constant equal to 8. Write code (within main) to form a moving average of the data your raw array storing the the results in the moving average array. How will you handle the first few points in your moving average where you have less than M raw data points to average? To what value will you set the first M-1 elements of your moving average array? There is not necessarily a single best answer here but you must justify your code design choice. Code must be typed. (10 pts)

BONUS: 5 pts Assume M is always defined as a power of 2. Implement your moving averager completely using integer variables and integer math. Why would this be desirable way to implement the code on an MSP430F5529? Problem #2 (15 pts) a) Express the following numbers as 16 bit unsigned integers 2309, 58002, 104. Show all your work. b) Express the following number as 16 bit signed (two's complement) integers -5, 7000, -32677. Show all your work. You are given the following 16-bit numbers 2A0Ah, C036h, and D800h. Each of these values could be interpreted as c. An unsigned number d. A sign-magnitude number e. A two's-complement number. Provide the base 10 equivalent of each value assuming each of these interpretations. Show all your work. Problem #3 (10 pts) a) Express the base 10 integer Y = 19765320 in BCD? b) Assume that the variable X is encoded in BCD. What is the decimal equivalent value of X if X = 0101100000100110b? Problem #4 (10 pts) a) What are the ASCII codes (in hex) for the characters '0', '1', '2', '3'.'9'? b) In lab you will regularly need to display numbers on the LCD screen. Therefore you will need to convert between integer digits and their ASCII representations and the reverse. What C code (variable declarations and 1 line of code) would you use convert a single decimal digit to its ASCII code? c) Assume the integer value D = 7531 has been converted for display into an array of ASCII values, declared as char D_asc[4]; What value (in hex) should stored in each array location so that the number would display properly (i.e. in left to right order) if printed on our Sharp LCD screen? Explain you reasoning. Hint: Check the Lab 0 demo code. D_asc[3] = D_asc[2] = D_asc[1] = D_asc[0] =

Problem #5 (25 pts) Convert the following numbers from decimal to IEEE 32-BIT floating point format. a) -128.75d b) 18.20d c) 9.666 The following numbers are encoded using 32-bit IEEE floating point format. Find the decimal values that they represent. Problem #6 (15 pts) d) C2A80000h e) 60C48000h In a table like the one below, show how the following variables would stored successively in memory by (a) a Little-endian CPU (b) a Big-endian CPU Show the values in hex (not binary) starting at address 02400 h. That is, variable ser_num is stored beginning at address 02400h. Label each address in your table. Remember each address in memory holds 1 byte. Is the MSP430F5529 big or little endian? char str[4] = Tst: ; // array of ASCII text // (No NULL terminator) float ss = -128.75; // IEEE 32-bit floating pt (see 5a) // an unsigned 64-bit integer long long unsigned int ser_num = Ox3EF5CBDF009CB6A4; int jj = -5; // a two's comp 16 bit integer int arr[2] = 32767, 4; // 2 element array of integers long unsigned int trp = 182092; Address Little Endian Big Endian... 02402 h 02401 h 02400 h

ECE2049 Homework #1 Submitted by: ECE Box #: << Be sure to include!! Date: Question 1-- 25 (5 pts) 2 -- 15 3 -- 10 4 -- 10 5 -- 25 6 15 Total: 100 (105) Grade YOU MUST ATTACH THIS COVER SHEET TO YOUR HW!!