Where are we? Compiler. translating source code (C or Java) Programs to assembly language And linking your code to Library code

Similar documents
Where we are going (today)

Where we are going (today)

Where we are going (today)

Bits, bytes and digital information. Lecture 2 COMPSCI111/111G

Overview. ELEC2041 Microprocessors and Interfacing. Lecture 7: Number Systems - II. March 2006.

CS61C : Machine Structures

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

CS61C : Machine Structures

CS 2630 Computer Organization. Meeting 13: Faster arithmetic and more operations Brandon Myers University of Iowa

Introduction to the Use of Computers

Many ways to build logic out of MOSFETs

Topic Notes: Bits and Bytes and Numbers

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

Learning Programme Fundamentals of data representation AS Level

Are Computers Smart? To a programmer: Lecture #1 Introduction & Numbers Andy Carle. Are Computers Smart? What are Machine Structures?

CS101 Lecture 04: Binary Arithmetic

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers

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

Topic Notes: Bits and Bytes and Numbers

Data III & Integers I

CSCI2467: Systems Programming Concepts

Data III & Integers I

ECE 250 / CS 250 Computer Architecture. C to Binary: Memory & Data Representations. Benjamin Lee

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

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

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

Bits, Words, and Integers

large units some names for large numbers CIS 2107 Chapter 2 Notes Part 1

CIS 2107 Chapter 2 Notes Part 1. Representing and Manipulating Information

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Physics 306 Computing Lab 5: A Little Bit of This, A Little Bit of That

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

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

LAB A Translating Data to Binary

CS 31: Intro to Systems Binary Representation. Kevin Webb Swarthmore College September 6, 2018

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

CS 110 Computer Architecture. Lecture 2: Introduction to C, Part I. Instructor: Sören Schwertfeger.

Here is a diagram of a simple computer system: (this diagram will be the one needed for exams) CPU. cache

Representing Information. Bit Juggling. - Representing information using bits - Number representations. - Some other bits - Chapters 1 and 2.3,2.

CS61C : Machine Structures

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

Bits, Bytes and Integers

COSC 6385 Computer Architecture. Storage Systems

CS 261 Fall Binary Information (convert to hex) Mike Lam, Professor

2. Integers. 9 * celsius / Celsius to Fahrenheit. Precedence. (9 * celsius / 5) + 32

2. Integers. 9 * celsius / Celsius to Fahrenheit. Precedence. (9 * celsius / 5) + 32

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

Unsigned Binary Integers

Unsigned Binary Integers

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

Express Yourself. The Great Divide

Review 1/2 MIPS assembly language instructions mapped to numbers in 3 formats. CS61C Negative Numbers and Logical Operations R I J.

2. Integers. 9 * celsius / Celsius to Fahrenheit. Precedence. (9 * celsius / 5) + 32

CS 33. Data Representation, Part 1. CS33 Intro to Computer Systems VII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

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

CS61C : Machine Structures

Page 1. Logistics. Introduction to Embedded Systems. My Records Indicate. Intel 4004 first single chip computer? Acronyms CS/ECE 6780/5780.

CS 2630 Computer Organization. Meeting 4: Intro to Architecture (specifically, MIPS) Brandon Myers University of Iowa

Processor. Lecture #2 Number Rep & Intro to C classic components of all computers Control Datapath Memory Input Output

CS 107 Lecture 2: Bits and Bytes (continued)

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

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

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

SIGNED AND UNSIGNED SYSTEMS

CS 1313 Spring 2000 Lecture Outline

CSE 351: The Hardware/Software Interface. Section 2 Integer representations, two s complement, and bitwise operators

CS107, Lecture 3 Bits and Bytes; Bitwise Operators

Processor. Lecture #2 Number Rep & Intro to C classic components of all computers Control Datapath Memory Input Output }

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

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

Hexadecimal Numbers. Journal: If you were to extend our numbering system to more digits, what digits would you use? Why those?

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

CS 61C: Great Ideas in Computer Architecture Lecture 2: Introduction to C, Part I

Memory, Data, & Addressing I

CS61C : Machine Structures

CS61C Machine Structures. Lecture 13 - MIPS Instruction Representation I. 9/26/2007 John Wawrzynek. www-inst.eecs.berkeley.

Binary Representations and Arithmetic

T02 Tutorial Slides for Week 2

1KOd17RMoURxjn2 CSE 20 DISCRETE MATH Fall

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng

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

4. Number Representations

ECE2049 E17 Lecture 2: Data Representations & C Programming Basics

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

15213 Recitation 2: Floating Point

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

COSC 6385 Computer Architecture Storage Systems

EMBEDDED SYSTEMS. Part I: Introduction and Hardware

Integers II. CSE 351 Autumn Instructor: Justin Hsia

Appendix. Numbering Systems. In This Appendix...

CprE 281: Digital Logic

Data III & Integers I

CS 2630 Computer Organization. Meeting 10/11: data structures in MIPS Brandon Myers University of Iowa

Operations, Operands, and Instructions

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

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

COMP2611: Computer Organization. Data Representation

Logic, Words, and Integers

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

11. A Computing Machine

Transcription:

Where are we? Compiler Instruction set architecture (e.g., MIPS) translating source code (C or Java) Programs to assembly language And linking your code to Library code How the software talks To the hardware Memory system Processor Datapath & Control Digital logic I/O system How a processor runs MIPS Programs! How switches (1 or 0) can be used to build Interesting functions: from integer arithmetic to programmable computers

CS 2630 Computer Organization Meeting 2: Bits, bytes, and memory Brandon Myers University of Iowa

Arithmetic on numbers Number to track the current line in the program Storing numbers

Caveat we will build everything from switches (on or off) A binary digit (or, bit) has two possible values 0 or 1 Just like a decimal digit has 10 possible values 0-9 Hundreds tens ones 193 10 = 1 9 3 fours twos ones 101 2 = 1 0 1 digit is a power of 10 digit is a power of 2

Peer instruction Translate the following binary numbers to decimal 10 2 = 10 111 2 = 10 10101 2 = 10 Bonus, translate this fractional number 11.01 2

Bits: for more than just numbers Bits can be used to encode (represent) ANY kind of data, yes any data Sample analog signal (displacement of microphone diaphragm) once every 23us (44.1KHz) store it digitally as an 8-bit number http://www.billboard.com/charts/ho t-100 https://upload.wikimedia.org/wikipedia/ commons/thumb/e/e6/microphone.svg/ 2000px-Microphone.svg.png https://upload.wikimedia.org/wikipedia/common s/thumb/d/d7/desktop_computer_clipart_- _Yellow_theme.svg/2000px- Desktop_computer_clipart_- _Yellow_theme.svg.png

Peer instruction How many unique values can you represent with 3 bits?

Peer instruction How many bits are needed to represent the number π? a) 1 bit b) infinite bits c) 3 bits d) 8 bits e) Can t be done

Counting with N bits (N=3) 111 000 001 110 010 101 100 011

What about negative integers? Make some space for them! 111 7 1106 5 101 000 0 Positive integers only ( unsigned ) 4 100 001 1 3 2 010 011 111-1 110-2 -3 101 000 0 Positive & negative integers ( signed ) -4 100 001 1 3 2 010 011

Two s complement just works! 11001 = (-1)*16 + (1)*8 + (0)*4 + (0)*2 + 1*1 = -16 + 9 = -7 1001 = (-1)*8 + (0)*4 + (0)*2 + 1*1 = -7 Or the invert and add 1 trick -7 = 11001 -> 00110 -> 00111 = 7 invert +1

Peer instructions: Two s complement and Hex 1. What is -11 10 in binary (using two s complement encoding for integers)? 2. A1 16 = 10

Another common base: 16 Binary (2) Decimal (10) Hexadecimal (16) 00000 0 0 00001 1 1 00010 2 2 00011 3 3 00100 4 4 00101 5 5 00110 6 6 00111 7 7 01000 8 8 01001 9 9 01010 10 A 01011 11 B 01100 12 C 01101 13 D 01110 14 E 01111 15 F 10000 16 10 10001 17 11

A note on conventions Sometimes we indicate a binary number with prefix 0b 10101 2 or 0b10101 Sometimes we indicate a hex number with prefix 0x FA41 16 or 0xFA41

Where we are going next Bits store whatever you want, including integers. How do we manipulate sequences of bits? 10110000 Q: How do we arrange bits in the memory of the computer? (why do we care? we want the computer to store many individual numbers) A: bytes and words 10110000 00001110 01000010 11110001 Q: How do we name or refer to all those individual numbers in memory? A: addresses and pointers 0 1 2 3 10110000 00001110 01000010 11110001

Arithmetic on numbers Number to track the current line in the program Storing numbers

Arithmetic on numbers Instruction memory Execution engine Data memory Number to track the current line in the program Storing numbers

can do bitwise operations (and other stuff) Instruction memory Execution engine Data memory organizes its bits as bytes and words

Back to bits soon, but first memory!

Organizing bits Byte: a unit of data In the MIPS architecture, bytes are 8-bits long and are the smallest unit of data the architecture gives a name to (more on names soon) True of most other modern architectures, too 00011010 1A 1 byte, perhaps storing the integer 26 10 We also like to write the value of a byte as two hex digits

Memory organization We think of memory as one big array of bytes 1A Analogy in Java? byte[] memory = new byte[num_bytes]; Just like every element in an array has an index, every byte in memory has an index, called its address. Use the address to find the byte to read or write it 1A

http://www.publicdomainpictures.net/view-image.php?image=2759

What to do now HW 1 and Quiz 1 New readings are up Buy your clicker license (if you don t yet have one) and go through getting started doc linked from the syllabus We ll try it Monday/Wed and start keeping track Friday Take a look at syllabus for office hours / Debug Your Brain

Organize bytes into machine words (note address in hex) 0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F 1A 32-bit words 64-bit words

Peer Instruction 32-bit words 64-bit words (note address in hex) 0000 0001 0002 0003 0004 0005 0006 0007 0008 1A MIPS has 32-bit addresses What is the largest number of bytes the memory of a MIPS computer can have? 0009 000A 000B 000C 000D 000E 000F

Looking at memory as words 0000 0004 0008 000C 0010 0014 0018 001C 0020 0024 0028

Storing values 0000 0004 store the value integer 15 10 at address 0x0008 0008 00 00 00 0F 000C 0010 0014 0018 001C 0020 0024 0028

Storing values store the value integer 15 10 at address 0x0014 store the value integer 20 10 at address 0x0000 0000 0004 0008 000C 0010 0014 0018 001C 0020 0024 0028 00 00 00 14 00 00 00 0F

Addresses can be values, too! store the value integer 15 10 at address 0x0014 store the value integer 20 10 at address 0x0000 store the value address 0x0014 at address 0x001C 0000 0004 0008 000C 0010 0014 0018 001C 0020 0024 0028 00 00 00 14 00 00 00 0F 00 00 00 14

Addresses can be values, too! store the value integer 15 10 at address 0x0014 store the value integer 20 10 at address 0x0000 store the value address 0x0014 at address 0x001C we say the word at address 0x001C is a pointer to the integer at address 0x0014 0000 0004 0008 000C 0010 0014 0018 001C 0020 0024 0028 00 00 00 14 00 00 00 0F 00 00 00 14

Addresses can be values, too! store the value integer 15 10 at address 0x0014 store the value integer 20 10 at address 0x0000 store the value address 0x0014 at address 0x001C we say the word at address 0x001C is a pointer to the integer at address 0x0014 store the value address 0x001C at address 0x0028 we say the word at address 0x0028 is a pointer to a pointer to an integer 0000 0004 0008 000C 0010 0014 0018 001C 0020 0024 0028 00 00 00 14 00 00 00 0F 00 00 00 14 00 00 00 1C

How arrays look in memory int[] arr = new int[3]; 0000 0004 0008 000C 0010 0014 0018 001C 0020 0024 0028

How arrays look in memory int[] arr = new int[3]; arr[0] = 13; 0000 0004 0008 000C 0010 0014 0018 001C 0020 0024 0028 00 00 00 0D

How arrays look in memory int[] arr = new int[3]; arr[0] = 13; arr[1] = 10; 0000 0004 0008 000C 0010 0014 0018 001C 0020 0024 0028 00 00 00 0D 00 00 00 0A

How arrays look in memory int[] arr = new int[3]; arr[0] = 13; arr[1] = 10; arr[2] = 16; 0000 0004 0008 000C 0010 0014 0018 001C 0020 0024 0028 00 00 00 0D 00 00 00 0A 00 00 00 10

Peer instruction Suppose we allocate this array: int[] arr = new int[7]; and Java decided to put the first byte of the array (first byte of arr[0]) at address 0x04 What is the address of arr[5]? a. 0x04 b. 0x14 c. 0x09 d. 0x54 e. 0x05 f. 0x18 address= base address + index * element_size

Size of data types (in bytes) Java data type size in 32-bit architecture boolean 1 1 byte 1 1 short 2 2 int 4 4 long 8 8 float (later!) 4 4 reference (stores a memory address) 4 8 size in 64-bit architecture slide inspired by UW CSE351

Administrivia: More office hours! Xin s office hours now scheduled! Monday 4:30pm - 6:00 Friday 9:30am 11 101N in Maclean Hall (MLH)

Aside: naming powers of two One of our favorite formulas: how many unique things can you represent with N bits? 2 N things Naming conventions N =? name Close (but not equal!) to power of 10 10 Kibi (Ki) 10 3 or Kilo (K) 20 Mebi (Mi) 10 6 or Mega (M) 30 Gibi (Gi) 10 9 or Giga (G) 40 Tebi (Ti) 10 12 or Tera (T) 50 Pebi (Pi) 10 15 or Peta (P) 60 Exbi (Ei) 10 18 or Exa (E) Name these numbers of bytes: 2 11 bytes = 2 32 bytes = 2 59 bytes =

Where we are going (today) Bits store whatever you want, including integers. How do we manipulate sequences of bits? 10110000 Q: How do we arrange bits in the memory of the computer? (why do we care? we want the computer to store many individual numbers) A: bytes and words 10110000 00001110 01000010 11110001 Q: How do we name or refer to all those individual numbers in memory? A: addresses and pointers 0 1 2 3 10110000 00001110 01000010 11110001 NEXT DONE (for now) DONE (for now)

Changing the number of bits Often we need to change the number of bits we are using to store a number (why?) 12 10 using 4 bits is 1100 2 If we store it in 8 bits: 00001100 2-5 10 using 4 bits is: 1011 If we store it in 8 bits: 2 We call this operation sign extension: copy the leftmost bit in 4-bit number to the new 4 leftmost bits in the 8-bit number

Representing sets with bits 4-bit vector represents subsets of {3,2,1,0} 1 means in the set, 0 means not in the set A is the set {1,0}, encoded as 0011 B is the set {2,0}, encoded as 0101 Set operations using bitwise operators A&B Intersection 0001 (1 iff both are 1) A B Union 0111 (1 iff at least one 1) A^B symmetric difference 0110 (1 iff exactly one 1) ~B complement 1010 (1 iff 0) slide inspired by UW CSE351

Shift shift: move bits left or right Left shift: 5 << 2 0 0 1 0 1 1 0 1 0 0 Right shift: 5 >> 1 0 0 1 0 1 0 0 0 1 0

Peer instruction What is the integer result from evaluating this expression? (assume integers are 32 bits) (7 << 2) & 15

Let s play a card game Come up with a binary encoding for a 52-card deck Slide inspired by CSE351 Spring 2016

Operations on a pair of cards We want the following operations to be easy to implement Compare two cards, which is higher value? Compare two cards, are they the same suit?

Where we are headed next can do bitwise operations (and other stuff) Instruction memory Execution engine Data memory Stores programs! organizes its bits as bytes and words

What to do now HW 1 is out today: due next Thursday Buy your clicker license (if you don t yet have one) and go through getting started doc Vote on Debug Your Brain availability if you haven t yet < 30 posts on the Introduce yourself discussion thread; go do it