Binary Numbers. The Basics. Base 10 Number. What is a Number? = Binary Number Example. Binary Number Example

Similar documents
Chapter 1. Hardware. Introduction to Computers and Programming. Chapter 1.2

Introduction. Chapter 1. Hardware. Introduction. Creators of Software. Hardware. Introduction to Computers and Programming (Fall 2015, CSUS)

Fundamentals of Programming (C)

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

5/17/2009. Digitizing Discrete Information. Ordering Symbols. Analog vs. Digital

The Binary Number System

Chapter 2 Bits, Data Types, and Operations

Data Representation and Binary Arithmetic. Lecture 2

Introduction to Decision Structures. Boolean & If Statements. Different Types of Decisions. Boolean Logic. Relational Operators

Fundamentals of Programming

Unit 3. Analog vs. Digital. Analog vs. Digital ANALOG VS. DIGITAL. Binary Representation

Chapter 2 Bits, Data Types, and Operations

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

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

3.1. Unit 3. Binary Representation

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

Number System (Different Ways To Say How Many) Fall 2016

Chapter 2 Bits, Data Types, and Operations

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

Chapter 2 Number System

Chapter 3. Information Representation

Lecture (09) x86 programming 8

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

Computer Processors. Part 2. Components of a Processor. Execution Unit The ALU. Execution Unit. The Brains of the Box. Processors. Execution Unit (EU)

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

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

ASSIGNMENT 5 TIPS AND TRICKS

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

CS341 *** TURN OFF ALL CELLPHONES *** Practice NAME

Number Systems II MA1S1. Tristan McLoughlin. November 30, 2013

Number Representations

Digital Representation

CMSC 313 Lecture 03 Multiple-byte data big-endian vs little-endian sign extension Multiplication and division Floating point formats Character Codes

DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes. Error Detection Codes

FA269 - DIGITAL MEDIA AND CULTURE

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

Oberon Data Types. Matteo Corti. December 5, 2001

Chapter 2 Bits, Data Types, and Operations

Bits and Bytes. Data Representation. A binary digit or bit has a value of either 0 or 1; these are the values we can store in hardware devices.

EE 109 Unit 2. Binary Representation Systems

Chapter 2 Bits, Data Types, and Operations

Chapter 8. Characters and Strings

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

Positional Number System

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, SPRING 2013

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, FALL 2012

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc.

Connecting UniOP to Datalogic Barcode Readers

PureScan - ML1. Configuration Guide. Wireless Linear Imager Wireless Laser scanner - 1 -

Do not start the test until instructed to do so!

Exercises Software Development I. 03 Data Representation. Data types, range of values, internal format, literals. October 22nd, 2014

Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School

Source coding and compression

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc.

2a. Codes and number systems (continued) How to get the binary representation of an integer: special case of application of the inverse Horner scheme

Variables and data types

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

CPSC 301: Computing in the Life Sciences Lecture Notes 16: Data Representation

Fundamental Data Types

4/14/2015. Architecture of the World Wide Web. During this session we will discuss: Structure of the World Wide Web

Chapter 7. Binary, octal and hexadecimal numbers

UNIT 2 NUMBER SYSTEM AND PROGRAMMING LANGUAGES

1. Character/String Data, Expressions & Intrinsic Functions. Numeric Representation of Non-numeric Values. (CHARACTER Data Type), Part 1

Do not start the test until instructed to do so!

Hardware. ( Not so hard really )

Do not start the test until instructed to do so!

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, FALL 2012

EXPERIMENT 8: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

APPENDIX B. ASSEMBLER DIRECTIVE SUMMARY

Programmable #182 Parallel Interface Cash Drawer Manual

RS-232 Control of the Advantage EQ281/8, EQ282/8 and Advantage SMS200

User s Manual. Xi3000 Scanner. Table of Contents

Table of Contents Sleep Settings How to Configure the Scanner. 7 Chapter 2 System Setup

This is great when speed is important and relatively few words are necessary, but Max would be a terrible language for writing a text editor.

n NOPn Unary no operation trap U aaa NOP Nonunary no operation trap i

EXPERIMENT 7: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

Number Systems Base r

Imperial College London Department of Computing

Xi2000-BT Series Configuration Guide

Configuration Manual PULSAR C CCD SCANNER. Table of Contents

User s Manual. Addendum to. Ranger Wedge Interface. Part No. 25-WEDGE-06A Ver. April 1999

8.2 User Defined Protocol Communication

Characters Lesson Outline

= Chapter 1. The Binary Number System. 1.1 Why Binary?

^BC Code 128 Bar Code (Subsets A, B, and C)

SPM723 Programmable Stereo Preamp/Mixer

First Data U.S. Debit Test Card Set. Version 1.20

RS-232 Control of the Advantage DRI

NC-1200 BARCODE SCANNER. Configuration Guide - 1 -

2D BARCODE SCANNER CA-SC-20200B

marson MT8200S 2D Handheld Scanner User Manual V / 6 / 25 - I -

Simple Data Types in C. Alan L. Cox

BARCODE SCANNER. Configuration Guide - 1 -

CSE 30 Spring 2006 Final Exam

Serial I/O. 4: Serial I/O. CET360 Microprocessor Engineering. J. Sumey

Lecture 10 Arrays (2) and Strings. UniMAP SEM II - 11/12 DKT121 1

Appendix A Developing a C Program on the UNIX system

Universal Asynchronous Receiver Transmitter Communication

Review. Single Pixel Filters. Spatial Filters. Image Processing Applications. Thresholding Posterize Histogram Equalization Negative Sepia Grayscale

Transcription:

The Basics Binary Numbers Part Bit of This and a Bit of That What is a Number? Base Number We use the Hindu-Arabic Number System positional grouping system each position represents a power of Binary numbers based on the same system use powers of 2 rather than The number 783 is... 4 3 2 7 8 + 7 + 8 + 3 = 783 3 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 3 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 4 Binary Number Example Binary Number Example The number is... 2 7 32 2 6 28 2 5 2 4 2 3 2 2 2 2 The number is... 64 6 8 4 2 2 7 32 2 6 28 2 5 2 4 2 3 2 2 2 2 64 6 8 4 2 28 + 32 + 8 + = 69 28 + 64 + 6 + 8 + 2 + = 29 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 5 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 6

Hexadecimal Numbers Hexadecimal Numbers Writing out long binary numbers is cumbersome and error prone As a result, computer scientists often write computer numbers in hexadecimal Hexadecimal is base-6 We only have...9 to represent digits So, hexadecimal uses A...F to represent...5 Hex Decimal Binary 2 2 3 3 4 4 5 5 6 6 7 7 Hex Decimal Binary 8 8 9 9 A B C 2 D 3 E 4 F 5 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 7 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 8 Hex Example Converting Binary to Hex = Easy The number A2C is... 6 3 6 2 6 6 496 256 6 A 2 C ( 256) + (2 6) + (2 ) = 264 Since 6 = 2 4, a single hex character can represent a total of 4 bits Byte can be represented with only 2 hex digits! When looking at raw data, editors, called Hex Editors, display data as groups of 2 hex digits 5 C /3/29 Sacramento State - Cook - CSc 35 - Spring 29 9 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 Bits and Bytes The Byte Everything in a modern computer is stored using combination of ones and zeros Bit is one binary digit either or shorthand for a bit is b Byte is a group of 8 bits e.g. shorthand for a byte is B Nibble bit /3/29 Sacramento State - Cook - CSc 35 - Spring 29 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 2 2

Hex & Binary Notation Hex & Binary Notation It gets confusing quick, so let's prepare Hexadecimal and binary notations use the same digits we use for decimal So, some numbers look like valid hex, decimal and binary Many programming languages have notation that specifies the base /3/29 Sacramento State - Cook - CSc 35 - Spring 29 4 Hex & Binary Notation Examples for 2 (2E 6 ) Notation Binary Hexadecimal For example is binary value 5? decimal value? hexadecimal value 257? This, obviously, can become problematic Subscript 2 2E 6 C++, Java, C# b x2e Visual Basic.NET &b &h2e VHDL 2## 6#2E# AT&T Assembly b x2e Intel Assembly y x2e or 2Eh Verilog 8'b2E 8'h2E /3/29 Sacramento State - Cook - CSc 35 - Spring 29 5 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 6 Characters Text in Programming Languages Press Any Key to Continue Computer often store and transmit textual data punctuation numerals 9 letter Each of these symbols is called a character and are the basis for written communication /3/29 Sacramento State - Cook - CSc 35 - Spring 29 8 3

Characters Characters Processors rarely know what a "character" is, and instead store each as an integer In this case, each character is given a unique value The letter "A", for instance, could have the value of, "B" is 2, etc Characters and their matching values are a character set There have been many characters sets developed over time /3/29 Sacramento State - Cook - CSc 35 - Spring 29 9 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 2 Character Sets ASCII Chart Control characters ASCII 7 bits 28 characters uses a full byte, one bit is not used created in the 967 EBCDIC Alternative system used by old IBM systems Not used much anymore 2 3 4 5 6 7 8 9 A B C D E F NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI DLE DC DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US 2 sp! " # $ % & ' ( ) * +, -. / 3 2 3 4 5 6 7 8 9 : ; < = >? 4 @ A B C D E F G H I J K L M N O 5 P Q R S T U V W X Y Z [ \ ] ^ _ 6 ` a b c d e f g h i j k l m n o 7 p q r s t u v w x y z { } ~ DEL /3/29 Sacramento State - Cook - CSc 35 - Spring 29 2 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 22 Useful Control Characters ASCII Codes 2 3 4 5 6 7 8 9 A B C D E F NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI DLE DC DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US 2 sp! " # $ % & ' ( ) * +, -. / Each character has a unique value The following is how "OMG" is stored in ASCII 3 2 3 4 5 6 7 8 9 : ; < = >? 4 @ A B C D E F G H I J K L M N O 5 P Q R S T U V W X Y Z [ \ ] ^ _ 6 ` a b c d e f g h i j k l m n o 7 p q r s t u v w x y z { } ~ DEL Binary Hex Decimal O 4F 79 M 4D 77 G 47 7 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 23 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 24 4

ASCII Codes ASCII Codes ASCII is laid out very logically Alphabetic characters (uppercase and lowercase) are 32 "code points" apart 32 = 2 5 Uppercase and lowercase letters are just bit different Converting between the two is easy Binary Hex Decimal Hex Binary A 4 a 6 A 65 4 a 97 6 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 25 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 26 ASCII: Number Characters ASCII: Number Characters ASCII code for is 3h The characters to 9 can be easily converted to their binary values Notice that the binary value is stored in the lower nibble 2 3 4 5 6 7 8 Character Binary clear the upper nibble Binary-And Binary Character set the upper nibble to Binary-Or 2 3 4 5 6 7 8 9 9 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 27 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 28 Unicode Character Set Unicode Character Set ASCII is only good for the United States Other languages need additional characters Multiple competing character sets were created Unicode was created to support every spoken language Developed in Mountain View, California Originally used 6 bits that's over 65, characters! includes every character used in the World Expanded to 2 bits 2 million characters! now supports every character ever created Unicode can be stored in different formats /3/29 Sacramento State - Cook - CSc 35 - Spring 29 29 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 3 5

High-Level Programming What are Programs? It's all just a bunch of bytes You are used to writing programs in high level programming languages C# Java Python Visual Basic /3/29 Sacramento State - Cook - CSc 35 - Spring 29 32 High-Level Programming Computer Processors These are third-generation languages They and are designed to isolate you from architecture of the machine This layer of abstraction makes programs "portable" between systems The Central Processing Unit (CPU) is the most complex part of a computer In fact, it is the computer It works far different from a high-level language /3/29 Sacramento State - Cook - CSc 35 - Spring 29 33 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 34 Computer Processors Instructions Over time, thousands of processors were developed Intel x86 IBM PowerPC MOS 652 ARM Processors do not have the constructs you find in highlevel languages Blocks If Statements While Statements etc /3/29 Sacramento State - Cook - CSc 35 - Spring 29 35 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 36 6

Instructions Instructions Processors can only perform a series of simple tasks These are called instructions add two values together move a value jump to a memory location These instructions are used to create all logic needed by a program We will cover how to do this during the semester /3/29 Sacramento State - Cook - CSc 35 - Spring 29 37 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 38 Processor Instruction Set A processor's instruction set defines all the available instructions The instructions and their respective formats are very different for each processor Registers Where the work is done /3/29 Sacramento State - Cook - CSc 35 - Spring 29 39 Registers What exactly is a register? In high level languages, you put active data into variables However, it works quite different on processors All computations are performed using registers A register is a location, on the processor itself, that is used to store temporary data Think of it as a special global "variable" Some are accessible and usable by a programs, but many are hidden /3/29 Sacramento State - Cook - CSc 35 - Spring 29 4 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 42 7

What are registers used for? General Purpose Registers Registers are used to store anything the processor needs to keep to track of Designed to be fast! the result of calculations status information memory location of the running program and much more General Purpose Registers (GPR) don't have a specific purpose They are designed to be used by programs however they are needed Often, you must use registers to perform calculations /3/29 Sacramento State - Cook - CSc 35 - Spring 29 43 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 44 Register Files All the related registers are grouped into a register file Different processors access and use their register files in very different ways Some processors support multiple files Machine Language The raw bytes of your program /3/29 Sacramento State - Cook - CSc 35 - Spring 29 45 Machine Language Machine Language The instructions, that are actually executed on the processor, are a series of bytes In this raw binary form, instructions are stored in machine language Each instruction is in a compact binary form Easy for the processor to interpret and execute Some instructions are take more bytes than others not all are equal /3/29 Sacramento State - Cook - CSc 35 - Spring 29 47 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 48 8

Instruction Encoding Operation Codes Each instruction must contain everything the processor needs to know to do something So, if you want it to add 2 registers, it has to specify which ones Each instruction has a unique operation code (Opcode) This value that specifies the exact operation to be performed by the processor Assemblers use friendly names called mnemonics /3/29 Sacramento State - Cook - CSc 35 - Spring 29 49 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 5 Typical Instruction Format Machine Code Example (not x86) The opcode is, typically, followed by various operands what data is to be used These can be register codes, addressing data, literal values, etc ADD %r, %r2 Opcode for ADD r r2 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 5 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 52 Computer Memory What is Memory? Its um. I forgot. Programs access and manipulate memory far more than you realize So, understanding it is vital to becoming a great assembly programmer and understanding computer architecture /3/29 Sacramento State - Cook - CSc 35 - Spring 29 54 9

What is Memory? Memory Addresses Memory is essentially an enormous array It is also, sometimes, referred to as storage It stores both running programs and their related data Memory is divided into a storage locations that can hold byte (8 bits) of data Each byte has an address unique value that refers to that specific byte used to locate the exact byte the processor wants 2 3 4 Memory /3/29 Sacramento State - Cook - CSc 35 - Spring 29 55 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 56 What is Memory? Memory Contains Data & Programs So, each address is conceptually the same as the "index" in array terminology and you will write access memory as would an array 2 3 4 Memory Each box represents a byte Computer Memory Instructions Data /3/29 Sacramento State - Cook - CSc 35 - Spring 29 57 /3/29 Sacramento State - Cook - CSc 35 - Spring 29 58 Memory Contains Data & Programs Data and instructions are just binary numbers (stored in a series of bytes) and are stored together Appreciating this is vital to understanding computer architecture /3/29 Sacramento State - Cook - CSc 35 - Spring 29 59