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

Similar documents
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 HW #1-- C programming and Binary Number Representations (DUE Friday 8/31/2018 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 9/1/2017 At the BEGINNING of class)

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

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

ECE2049 E17 Lecture 2: Data Representations & C Programming Basics

COMP2611: Computer Organization. Data Representation

Computer Systems Programming. Practice Midterm. Name:

COMP2121: Microprocessors and Interfacing. Number Systems

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

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

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

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

MACHINE LEVEL REPRESENTATION OF DATA

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

Lecture 2: Number Systems

World Inside a Computer is Binary

Byte Ordering. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

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

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

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

Declaration. Fundamental Data Types. Modifying the Basic Types. Basic Data Types. All variables must be declared before being used.

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

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

1.1. Unit 1. Integer Representation

Integer Representation Floating point Representation Other data types

CS 31: Intro to Systems Binary Representation. Kevin Webb Swarthmore College January 27, 2015

Data Types. Data Types. Integer Types. Signed Integers

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

SIGNED AND UNSIGNED SYSTEMS

Binary Representations and Arithmetic

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

Final Labs and Tutors

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

CS/ECE 5780/6780: Embedded System Design

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

Data Representation and Binary Arithmetic. Lecture 2

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

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

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

Representation of Information

/* defines are mostly used to declare constants */ #define MAX_ITER 10 // max number of iterations

CS Programming In C

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

Chapter 4: Data Representations

ET355 Microprocessors Thursday 6:00 pm 10:20 pm

Bits and Bytes January 13, 2005

Number System. Introduction. Decimal Numbers

MIPS Assembly: Practice Questions for Midterm 1 Saving to and Loading from Memory CS 64: Computer Organization and Design Logic Lecture #6

CS107, Lecture 3 Bits and Bytes; Bitwise Operators

17. Instruction Sets: Characteristics and Functions

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

Bits, Bytes, and Integers Part 2

Survey. Motivation 29.5 / 40 class is required

Logic Circuits I ECE 1411 Thursday 4:45pm-7:20pm. Nathan Pihlstrom.

Computer Organization and Assembly Language. Lab Session 01

Exercise: Using Numbers

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

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

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

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

Few reminders and demos

Number Systems and Conversions UNIT 1 NUMBER SYSTEMS & CONVERSIONS. Number Systems (2/2) Number Systems (1/2) Iris Hui-Ru Jiang Spring 2010

ECOM 2325 Computer Organization and Assembly Language. Instructor: Ruba A.Salamah INTRODUCTION

Integers II. CSE 351 Autumn Instructor: Justin Hsia

Digital Logic. The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer.

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

Numbering systems. Dr Abu Arqoub

CS101 Lecture 04: Binary Arithmetic

Computer Organization

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

Run time environment of a MIPS program

3.5 Floating Point: Overview

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

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

M1 Computers and Data

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

LING 388: Computers and Language. Lecture 5

Outline. Review of Last Week II. Review of Last Week. Computer Memory. Review Variables and Memory. February 7, Data Types

CS107 Handout 13 Spring 2008 April 18, 2008 Computer Architecture: Take II

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

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

Arithmetic and Bitwise Operations on Binary Data

Data Representation Floating Point

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

EE 109 Unit 2. Binary Representation Systems

QUIZ ch.1. 1 st generation 2 nd generation 3 rd generation 4 th generation 5 th generation Rock s Law Moore s Law

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

Data Representation Floating Point

Inf2C - Computer Systems Lecture 2 Data Representation

ICS Instructor: Aleksandar Kuzmanovic TA: Ionut Trestian Recitation 2

ECE 372 Microcontroller Design Assembly Programming Arrays. ECE 372 Microcontroller Design Assembly Programming Arrays

Lecture 4: Instruction Set Architecture

Tutorial 1: C-Language

CS107, Lecture 2 Bits and Bytes; Integer Representations

Transcription:

ECE2049: Embedded Computing in Engineering Design C Term Spring 2018 Lecture #3: Of Integers and Endians (pt. 2) Reading for Today: Davies Ch 2, MSP430 User's Guide Ch 6.1, 6.3 Reading for Next Class: Davies Ch 2, MSP430 User's Guide Ch 6.1, 6.3 Homework #1 (on the web): Due Friday 1/19 (on paper at the beginning of class) Lab #0 (on the web): Report (on paper) due Tues 1/23(in class) Code (zipped archive of modified demo) submit on-line Last class: There are a number of standard formats for encoding data into binary representations for use inside computers. Examples include Char = 1 byte = Can hold ASCII characters OR small integers Integers = Unsigned, 2's comp., Sign-magnitude This Class: Finish discussion of data formats -- Floating Point and Endian discussion Binary Coded Decimal = A legacy format. Each decimal digit encoded in 4-bits 367 = Hexidecimal (hex) Numbers: Base 16 KNOW THESE!!! --> 1 Hex character represent values from 0 to 15d using digits 0 F h DEC BIN HEX DEC BIN HEX What is 158d =? in hex 0 0000 0 8 1000 8 1 0001 1 9 1001 9 2 0010 2 10 1010 A 3 0011 3 11 1011 B 4 0100 4 12 1100 C 5 0101 5 13 1101 D 6 0110 6 14 1110 E 7 0111 7 15 1111 F

Conversion between hex and binary is piece of cake! Just convert each hex digit to a binary nibble... 1001 1110b = 158d Or vise versa 2AC4h = 2 A C 4 Ex: Review: What decimal value does 8008h represent as an (a) unsigned integer, (b) 2's comp integer ( c) sign-magnitude integer (d) BCD (e) Two ASCII characters?

SO, how EXACTLY are the variables declared in programs stored? >> Depends on the compiler being used. In CCS for the MSP430 the types defined as int a; // 16 bit signed (2's comp)integer float b; // 32 bit IEEE floating point char c,h; // 8 bit (unsigned) integer unsigned int d; // 16 bit unsigned integer long int e; // 32 bit signed integer (2's comp) double f; // 64 bit IEEE floating point SIZE and TYPE of variable define the range of values that they can represent! The VALUE stored in a variable CAN NOT exceed the fixed variable size. Variables will overflow or roll over if value exceed variable size Ex: What is the value of h in each loop? c = 253; for (a = 0; a < 4; a++) { h = c + (char) a; // cast not strictly needed } What about Fraction Numbers??? >> There are 2 conventions: Fixed point and Floating Point Fixed point: Binary radix point assigned a fixed location in byte (or word) 00000.101 = Granularity or precision is function of the number of fractional bits assigned --> 4 fractional bits = 2-4 = 0.0625 = smallest fraction >> Often (usually) data just scaled to integer representation

Floating Point (IEEE Standard) : Used to better approximate real valued decimal numbers to a prescribed number of decimal places Single Precision (32 bits): S EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF Value = (-1) S 2 (E-127) * (1.F) Ex: What floating point value is represented by CAAA00? Ex: Represent -5.375 as a Single Precision number -5.375

>> How many decimal digits of precision does 32-bit floating point have? >> The effective range of 32-bit floating point variable is ± 10 44.85 to 10 38..53 >> How many different numbers can be represented by a 32 bit float? The MSP430, like Intel 80x86 family processors, is Little Endian --> Each location in computer memory typically holds 1 byte. Storing a 16-bit word takes 2 bytes. The lease significant byte of each 16 bit word is stored first (in the lower memory address) then the more significant byte -- > Low Byte, High Byte --> For double words the lower word is stored first then the upper word Ex: How is 65540 decimal = 00010004h is stored in memory at address 024 Little Endian Address Byte Value 02403h 02402h 02401h 024 01h 04h...... A memory dump from CCS shows addresses left to right starting with address 024 0x02400 = 04 00 01 00... << Bytes appear out of order when read L to R Many other RISC processors are Big Endian. The higher byte (big end) is stored first then the lower byte. BIG Endian Address Byte Value 02403h 02402h 02401h 024 04h 01h......

A memory dump from a big endian processor would also show addresses left to right starting with address 024 0x02400= 00 01 00 04... << But bytes appear in order when read L to R Here is an example of being Endian-ed! A nice plot of a file of unsigned integers as created on a little endian machine. Below is a plot of the same data file having being read in as unsigned integers on a big endian machine. The data is good! It is the same as above! All that has changed is the endianness of the machine that read the data. The table below shows the first few unsigned integer values from the data file created on the little endian computer as read by both of the machines. The byte swap is evident in the hexadecimal values.

Read as Little Endian Read as Big Endian 8178 1FF2 h 61983 F21F h 8193 2001 h 288 0120 h 8194 2002 h 544 0220 h 8182 1FF6 h 63007 F61F h 8201 2009 h 2336 0920 h 8201 2009 h 2336 0920 h >> Endianness DOES NOT affect order of array elements! How would the following variables be stored in memory on the MSP430F5529 (starting at address 024? How would they be stored on a Big Endian microprocessor? unsigned int a = 0x00FF; long int b[2] = {65540, 8201}; char c = 'C'; // ASCII code is 0x43 Address Little Endian (MSP430F5529) Big Endian BTW, The Byte Order for data transmitted over the Internet = BIG ENDIAN!!!