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

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

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

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: Embedded Computing in Engineering Design C Term Spring Lecture #3: Of Integers and Endians (pt. 2)

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

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

ECE2049 E17 Lecture 2: Data Representations & C Programming Basics

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

Computer Systems Programming. Practice Midterm. Name:

Solutions - Homework 2 (Due date: October 4 5:30 pm) Presentation and clarity are very important! Show your procedure!

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

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

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

Arithmetic and Bitwise Operations on Binary Data

17. Instruction Sets: Characteristics and Functions

World Inside a Computer is Binary

Integers II. CSE 351 Autumn 2018

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

15110 PRINCIPLES OF COMPUTING SAMPLE EXAM 2

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

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

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

Grading: 3 pts each part. If answer is correct but uses more instructions, 1 pt off. Wrong answer 3pts off.

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

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

CprE 281: Digital Logic

COMP2611: Computer Organization. Data Representation

M1 Computers and Data

ECE/CS 252 Fall 2011 Homework 4 (25 points) // Due in Lecture Mon Oct. 17, 2011

Description Hex M E V smallest value > largest denormalized negative infinity number with hex representation 3BB0 ---

Representation of Information

Arithmetic and Bitwise Operations on Binary Data

Computer Organization & Systems Exam I Example Questions

Jin-Soo Kim Systems Software & Architecture Lab. Seoul National University. Integers. Spring 2019

LING 388: Computers and Language. Lecture 5

CMPSC 311 Exam 2. March 27, 2015

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

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

General Instructions. You can use QtSpim simulator to work on these assignments.

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

Integers II. CSE 351 Autumn Instructor: Justin Hsia

NAME: 1a. (10 pts.) Describe the characteristics of numbers for which this floating-point data type is well-suited. Give an example.

SIGNED AND UNSIGNED SYSTEMS

1.1. Unit 1. Integer Representation

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

Data Storage. August 9, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 August 9, / 19

Midterm Exam Review Slides

Survey. Motivation 29.5 / 40 class is required

Real Numbers finite subset real numbers floating point numbers Scientific Notation fixed point numbers

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

CSE351: Memory, Data, & Addressing I

Byte Ordering. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

UW CSE 351, Winter 2013 Final Exam

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

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

Binary Representations and Arithmetic

Part 2,Number Systems Questions

Integers II. CSE 351 Autumn Instructor: Justin Hsia

Hardware: Logical View

9/3/2015. Data Representation II. 2.4 Signed Integer Representation. 2.4 Signed Integer Representation

Computer Organization and Architecture (CSCI-365) Sample Final Exam

Here is a C function that will print a selected block of bytes from such a memory block, using an array-based view of the necessary logic:

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

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

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

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

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

But first, encode deck of cards. Integer Representation. Two possible representations. Two better representations WELLESLEY CS 240 9/8/15

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

Programming Studio #1 ECE 190

231 Spring Final Exam Name:

Bits, Bytes, and Integers Part 2

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

Homework 1 graded and returned in class today. Solutions posted online. Request regrades by next class period. Question 10 treated as extra credit

Under the Hood: Data Representation. Computer Science 104 Lecture 2

CS2630: Computer Organization Homework 1 Bits, bytes, and memory organization Due January 25, 2017, 11:59pm

CS367 Test 1 Review Guide

Memory, Data, & Addressing I

Level ISA3: Information Representation

Memory, Data, & Addressing II

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017

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

Computer Architecture I Midterm I

CS & IT Conversions. Magnitude 10,000 1,

Content. Information Coding. Where are we? Where are we? Bit vectors (aka Words )

15-110: Principles of Computing, Spring 2018

Binary Codes. Dr. Mudathir A. Fagiri

unused unused unused unused unused unused

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,...

Programming Studio #1 ECE 190

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

Final Exam. 11 May 2018, 120 minutes, 26 questions, 100 points

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Integer Representation Floating point Representation Other data types

Computer (Literacy) Skills. Number representations and memory. Lubomír Bulej KDSS MFF UK

Computer System and programming in C

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

SECONDARY SCHOOL, L-IMRIEĦEL HALF YEARLY EXAMINATIONS 2016/2017

Transcription:

Due: Thursday, 26 May 2016 by 5pm Submission notes: For full credit, please show your work and denote your answers with a circle or a box. Always write and draw your diagrams neatly! We cannot be expected to GUESS what you meant to write! Please staple your work before submitting and remove any ruffled edges from notebook paper. Points for each problem are as indicated. Some portions of problems are marked as BONUS, which count as extra credit. 1. (20 pts) You are given three 16-bit values shown below. Each of these values can be interpreted as: An unsigned number A sign-magnitude number A two s complement number Provide the decimal (base 10) equivalent of each value for each of these interpretations. Show your work. a. 0x2040 b. 0x4BE5 c. 0xBEEF 2. (10 pts) Binary Coded Decimal (or BCD) is a legacy format that uses 4 bits to represent each digit in a decimal number. a. Express the decimal integer 42517 in BCD. b. If the number N = 0110 0111 0001 0101 0011 1001 is encoded in BCD, what is the decimal value of N? 3. (10 pts) Assume that our class will have 3 exams, 5 labs, and 4 or 5 homework assignments. All exams are at most 100 points; homeworks and labs may have varying point values, but are never more than 150 points. All assignment and exam grades always have integer values (we always round up!). Consider the following code to compute the average of your exam grades: #define NUM_EXAMS (3) char exam_grades[3]; char exam_avg; exam_avg = ((int)(exam_grades[0]+exam_grades[1]+exam_grades[2]))/num_exams; a. Are the variables used appropriately sized? Explain why or why not. b. The last line of the example uses a cast. What is a cast in C programming? Is it necessary in this code? Explain. ECE2049-E16 (Instructor: N. DeMarinis) Page 1 of 5

4. (20 pts) In a table like the one below, show how the following variables would be stored in memory by: A Little-endian CPU A Big-endian CPU int ii = -4; // Two s complement 16-bit integer long long unsigned int ser_num = 0x12345A6B7C8D9EFF; // An unsigned 64-bit integer char *class = ECE2049 ; // Character array containing ASCII text int arr[3] = 1, -32768, -1; // 3-element array of int long unsigned int count = 72342; a. First, determine the representation of each variable listed above in hex. b. Next, arrange the variables as they would be stored in memory starting at address 0x4300. To do this, make a table similar to the one below, labeling each address and denoting which byte would be stored in that address in each case. Remember that each address in memory holds 1 byte. Address Little Endian Big Endian 0x4302 0x4301 0x4300 Note: This table is usually drawn with the lowest memory address at the bottom of the table, as shown here: c. Is the MSP430 architecture we use in class big or little endian? d. (BONUS: 5 pts) What if we added one additional variable in the example above as shown below. Based on only the code below, what is the value of new_var? How is it arranged in memory? long unsigned int count = 72342; unsigned int new_var; ECE2049-E16 (Instructor: N. DeMarinis) Page 2 of 5

5. (10 pts) In C, there are often multiple ways to write code to solve a given problem. Rewrite the following code segment to use a for loop instead of a while loop and to use a switch statement instead of if/else statements. Your code should be typed. #define MAX_KEY_PRESS (20) unsigned char curr_key, press = 0; unsigned char key_hist[max_key_press]; while(press < MAX_KEY_PRESS) curr_key = getkey(); key_hist[press] = curr_key; if(curr_key == * ) leds_off(); buzzer_on(); else if(curr_key == # ) leds_off(); buzzer_off(); else leds_set_value(curr_key); press++; ECE2049-E16 (Instructor: N. DeMarinis) Page 3 of 5

6. (10 pts) Answer the following questions regarding execution of loops. Assume that the code below is executed on an MSP430 (ie, an int has a size of two bytes). a. In the following code segment, how many times does the loop iterate? What are the values of kk, mm, and inval (in decimal) at the beginning and end of the first loop, and the beginning and end of the final loop? unsigned int inval, out, kk = 0x0001, mm = 0x1000; char count = 1; while(kk!= 0) inval = (mm + kk) / kk; out = somefunction(inval); mm /= 2; kk = kk << 1; b. In the code segment below, what is the value of count in the last three loops? char count = 1; while(count > 0) // Do some things... count++; ECE2049-E16 (Instructor: N. DeMarinis) Page 4 of 5

7. (20 pts) This problem involves converting numbers in IEEE754 floating-point format. Express the following number as a 32-bit floating point value. Show your work, and express your final answer in hex: a. -32.875 The following 32-bit hexadecimal values encode a 32-bit floating point number. Find the decimal value it represents. Show your work. b. 0x422A8000 c. 0x3C800000 d. BONUS (5 pts): Express the number 19.3303 as a 32-bit floating point value. How accurate is the floating point representation? ECE2049-E16 (Instructor: N. DeMarinis) Page 5 of 5