Harry H. Porter, 2006

Similar documents
Number Representation

EE 109 Unit 6 Binary Arithmetic

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

17. Instruction Sets: Characteristics and Functions

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation

Number System. Introduction. Decimal Numbers

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

COMP Overview of Tutorial #2

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

data within a computer system are stored in one of 2 physical states (hence the use of binary digits)

Digital Arithmetic. Digital Arithmetic: Operations and Circuits Dr. Farahmand

Chapter. Computer Architecture

Positional notation Ch Conversions between Decimal and Binary. /continued. Binary to Decimal

Mark II Aiken Relay Calculator

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

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 1: Basic Concepts. Chapter Overview. Welcome to Assembly Language

CS & IT Conversions. Magnitude 10,000 1,

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

Chapter Overview. Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 1: Basic Concepts. Printing this Slide Show

11. A Computing Machine

Binary Representations and Arithmetic

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

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

Topic Notes: Bits and Bytes and Numbers

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

Compiler Design. Homework 1. Due Date: Thursday, January 19, 2006, 2:00

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

World Inside a Computer is Binary

Overview of the SPARC Architecture

Topic Notes: Bits and Bytes and Numbers

BINARY SYSTEM. Binary system is used in digital systems because it is:

INTEGER REPRESENTATIONS

Wednesday, February 4, Chapter 4

Survey. Motivation 29.5 / 40 class is required

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

Chapter 2 Number System

Wednesday, September 13, Chapter 4

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

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

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

COMP2611: Computer Organization. Data Representation

Course Syllabus [1/2]

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

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

2010 Summer Answers [OS I]

Computer Organization and Assembly Language. Lab Session 01

Chapter 1 Review of Number Systems

Octal and Hexadecimal Integers

Operations, Operands, and Instructions

M1 Computers and Data

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

Assembly Language Design

CS 101: Computer Programming and Utilization

Introduction to Computer Science-103. Midterm

Number Systems. TA: Mamun. References: Lecture notes of Introduction to Information Technologies (ITEC 1011) by Dr Scott MacKenzie

History of Computing. Ahmed Sallam 11/28/2014 1

CS 31: Intro to Systems Binary Arithmetic. Kevin Webb Swarthmore College January 26, 2016

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

Binary Values. CSE 410 Lecture 02

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

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

CHAPTER 1 Numerical Representation

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

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

MACHINE LEVEL REPRESENTATION OF DATA

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

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

Fundamentals of Programming Session 2

Representing numbers on the computer. Computer memory/processors consist of items that exist in one of two possible states (binary states).

COSC 243. Instruction Sets And Addressing Modes. Lecture 7&8 Instruction Sets and Addressing Modes. COSC 243 (Computer Architecture)

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

Module 2: Computer Arithmetic

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

Computer Organization

Number representations

Module 1: Information Representation I -- Number Systems

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

CS 64 Week 0 Lecture 1. Kyle Dewey

Beginning C Programming for Engineers

LAB A Translating Data to Binary

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

Arithmetic and Bitwise Operations on Binary Data

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

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

ECE 486/586. Computer Architecture. Lecture # 6

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

Number Systems and Computer Arithmetic

Signed Binary Numbers

Organisasi Sistem Komputer

Basic Assembly SYSC-3006

Chapter 2. Instruction Set. RISC vs. CISC Instruction set. The University of Adelaide, School of Computer Science 18 September 2017

Lecture 9. INC and DEC. INC/DEC Examples ADD. Arithmetic Operations Overflow Multiply and Divide

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

Instruction Set Architecture

CMPE223/CMSE222 Digital Logic Design. Positional representation

Instruction Sets: Characteristics and Functions

What is an Addressing Mode?

T02 Tutorial Slides for Week 2

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

Transcription:

The SPARC Computer Architecture Harry Porter Portland State University 1 CS-321 Lexer Parser Type Checking Intermediate Code Generation All semantic error checking finished in this phase IR - Intermediate Represenation CS-322 Optimization IR (same) Final Code Generation Assembly Code A Compiler Assembler / Linker Executable (e.g., an a.out file) 2

Lexer CS-321 Parser Type Checking Intermediate Code Generation IR - Intermediate Represenation CS-322 Optimization IR (same) Final Code Generation Machine Code A Compiler Option: Go straight to machine code...and skip the assembly step! Linker Executable (e.g., an a.out file) 3 Machine Code Assembly Code 10000010000000001000000000000011 add %g1,%g2,%g3 11000110001000000010000001010101 st %g3,mylocation...... Each architecture has its own Machine Code / Assembly Code Close correspondence...almost 1-to-1 Machine code: The bits that get loaded into memory The CPU interprets these bits as instructions Assembly code: Easier for humans to work with The assembler translates assembly code into machine code 4

A Spectrum Use all instructions and use them very well The Ideal Really good programmers Beginning Programmers Use only a few of the available instructions 5 A Spectrum Use all instructions and use them very well The Ideal Optimizing compiler Really good programmers Good compiler Beginning Programmers Workable Compiler Use only a few of the available instructions 6

Memory is byte addressable SPARC Basics Instructions are 4 bytes (32 bits) Addresses are 4 bytes (32 bits) The CPU is always executing in either System Mode (or supervisor mode ) Special instructions (load page table, perform I/O, other OS stuff...) User Mode (or program mode ) Compiler-generated code does not include system instructions We ll cover a subset of the SPARC instructions. 7 Byte 8 bits Basic Concepts 7 0 Halfword 16 bits = 2 bytes 15 0 Word 32 bits = 4 bytes 31 0 Doubleword 64 bits = 8 bytes 63 0 Quadword 128 bits = 16 bytes 127 0 8

Main Memory Organization 0 1 2 3 4 5 6 7 8 9 a b ffff fffb ffff fffc ffff fffd ffff fffe ffff ffff 7 0 byte 9 Main Memory Organization 0 1 2 3 4 5 6 7 8 9 a b Low Memory Addresses are 32 bits (up to 2 32 = 4 Gbytes) ffff fffb ffff fffc ffff fffd ffff fffe ffff ffff 7 0 byte High Memory 10

Address of this word Main Memory Organization 0 1 2 3 4 5 6 7 8 9 a b A WORD Low Memory Addresses are 32 bits (up to 2 32 = 4 Gbytes) ffff fffb ffff fffc ffff fffd ffff fffe ffff ffff 7 0 byte High Memory 11 Address of this word 31 0 Main Memory Organization 0 1 2 3 4 5 6 7 8 9 a b Low Memory MSB (Most significant byte) A WORD LSB (Least significant byte) Addresses are 32 bits (up to 2 32 = 4 Gbytes) ffff fffb ffff fffc ffff fffd ffff fffe ffff ffff 7 0 byte High Memory 12

Address of this word 31 0 Addresses are 32 bits (up to 2 32 = 4 Gbytes) Main Memory Organization 0 1 2 3 4 5 6 7 8 9 a b ffff fffb ffff fffc ffff fffd ffff fffe ffff ffff 7 0 byte Low Memory MSB (Most significant byte) A WORD LSB (Least significant byte) Big Endian Architecture (e.g., SPARC, Mac) High Memory 13 Address of this word Addresses are 32 bits (up to 2 32 = 4 Gbytes) Main Memory Organization 0 1 2 3 4 5 6 7 8 9 a b ffff fffb ffff fffc ffff fffd ffff fffe ffff ffff 7 0 byte Low Memory LSB (Least significant byte) A WORD MSB (Most significant byte) Little Endian Architecture (e.g., Intel) High Memory 14

Data Alignment Data stored in memory must be aligned according to the length of the data Byte Data can go at any address Halfword Data must be aligned addresses must be even numbers Word Data must be word aligned addresses must be divisible by 4 Doubleword Data must be doubleword aligned addresses must be divisible by 8 15 0000 0000 0000 0001 0000 0002 0000 0003 0000 0004 0000 0005 0000 0006 0000 0007 0000 0008 0000 0009 0000 000a 0000 000b 0000 000c 0000 000d 0000 000e 0000 000f 0000 0010 0000 0011 0000 0012 0000 0013 0000 0014 0000 0015 0000 0016 0000 0017 0000 0018 0000 0019 0000 001a 0000 001b 0000 001c 0000 001d 0000 001e 0000 001f doubleword doubleword doubleword doubleword Doubleword addresses end in a number divisible by 8: 0, 8 In binary: ---- ---- ---- ---- ---- ---- ---- -000 16

0000 0000 0000 0001 0000 0002 0000 0003 0000 0004 0000 0005 0000 0006 0000 0007 0000 0008 0000 0009 0000 000a 0000 000b 0000 000c 0000 000d 0000 000e 0000 000f 0000 0010 0000 0011 0000 0012 0000 0013 0000 0014 0000 0015 0000 0016 0000 0017 0000 0018 0000 0019 0000 001a 0000 001b 0000 001c 0000 001d 0000 001e 0000 001f word word word word word word word word Word addresses end in a number divisible by 4: 0, 4, 8, c In binary: ---- ---- ---- ---- ---- ---- ---- --00 17 0000 0000 0000 0001 0000 0002 0000 0003 0000 0004 0000 0005 0000 0006 0000 0007 0000 0008 0000 0009 0000 000a 0000 000b 0000 000c 0000 000d 0000 000e 0000 000f 0000 0010 0000 0011 0000 0012 0000 0013 0000 0014 0000 0015 0000 0016 0000 0017 0000 0018 0000 0019 0000 001a 0000 001b 0000 001c 0000 001d 0000 001e 0000 001f Halfword addresses end in an even number: 0, 2, 4, 6, 8, a, c, e In binary: ---- ---- ---- ---- ---- ---- ---- ---0 18

Decimal Number Representation 4037 = 4000 + 30 + 7 =... + 0!10000 + 4!1000 + 0!100 + 3!10 + 7!1 =... + 0!10 4 + 4!10 3 + 0!10 2 + 3!10 1 + 7!10 0 Base 10:... + X!10 4 + X!10 3 + X!10 2 + X!10 1 + X!10 0 Set of numerals (the digits ): { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } 19 Hexadecimal Number Representation Base 16:... + X!16 4 + X!16 3 + X!16 2 + X!16 1 + X!16 0... + X!65536 + X!4096 + X!256 + X!16 + X!1 Set of numerals: { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F } 3A0F =... + 0!16 4 + 3!16 3 + A!16 2 + 0!16 1 + F!16 0 =... + 0!65536 + 3!4096 + A!256 + 0!16 + F!1 =... + 0!65536 + 3!4096 + 10!256 + 0!16 + 15!1 = 12,288 + 2,560 + 15 = 14,863 (in decimal) 20

Binary Number Representation Base 2:... + X!2 5 + X!2 4 + X!2 3 + X!2 2 + X!2 1 + X!2 0... + X!32 + X!16 + X!8 + X!4 + X!2 + X!1 Set of numerals: { 0, 1} 110101 =... + 1!2 5 + 1!2 4 + 0!2 3 + 1!2 2 + 0!2 1 + 1!2 0 =... + 1! 32 + 1! 16 + 0!8 + 1!4 + 0!2 + 1!1 = 32 + 16 + 4 + 1 = 53 (in decimal) 21 One-to-one correspondence between hex and binary; 3 A 0 F 0011 1010 0000 1111 Byte (8 bits) Hex: 3A Binary: 0011 1010 Halfword (16 bits) Hex: 3A0F Binary: 0011 1010 0000 1111 Word (32 bits) Hex: 3AOF 12D8 Binary: 0011 1010 0000 1111 0001 0010 1101 1000 Decimal Binary Hex 0 0000 0 1 0001 1 2 0010 2 3 0011 3 4 0100 4 5 0101 5 6 0110 6 7 0111 7 8 1000 8 9 1001 9 10 1010 A 11 1011 B 12 1100 C 13 1101 D 14 1110 E 15 1111 F 22

Bad match with byte alignment Octal Notation 1 5 2 2 6 1 1 1 0 1 0 1 0 0 1 0 1 1 0 0 0 1 byte The numbers get too long. Word (32 bits) Octal: 12305570426 Hex: 3A0F 12D8 byte Every octal looks like a decimal number (and often they get confused). 263 8 = 179 10 263 10 = 263 10 263 16 = 611 10 C Notation for octals (leading zero is significant!) 0263 Decimal Binary Octal 0 000 0 1 001 1 2 010 2 3 011 3 4 100 4 5 101 5 6 110 6 7 111 7 23 Unsigned Number Representation 8-bits Always non-negative 0,1,2,... 255 0,1,2,... 2 8-1 Value (in decimal) Binary Hex 0 0000 0000 00 1 0000 0001 01 2 0000 0010 02 3 0000 0011 03 4 0000 0100 04 5 0000 0101 05 6 0000 0110 06 7 0000 0111 07......... 252 1111 1100 FC 253 1111 1101 FD 254 1111 1110 FE 255 1111 1111 FF 24

Unsigned Number Representation 32-bits Always non-negative 0,1,2,... 4,294,967,295 0,1,2,... 2 32-1 Value (in decimal) Binary Hex 0 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 1 0000 0000 0000 0000 0000 0000 0000 0001 0000 0001 2 0000 0000 0000 0000 0000 0000 0000 0010 0000 0002 3 0000 0000 0000 0000 0000 0000 0000 0011 0000 0003 4 0000 0000 0000 0000 0000 0000 0000 0100 0000 0004 5 0000 0000 0000 0000 0000 0000 0000 0101 0000 0005 6 0000 0000 0000 0000 0000 0000 0000 0110 0000 0006 7 0000 0000 0000 0000 0000 0000 0000 0111 0000 0007......... 4,294,967,292 1111 1111 1111 1111 1111 1111 1111 1100 FFFF FFFC 4,294,967,293 1111 1111 1111 1111 1111 1111 1111 1101 FFFF FFFD 4,294,967,294 1111 1111 1111 1111 1111 1111 1111 1110 FFFF FFFE 4,294,967,295 1111 1111 1111 1111 1111 1111 1111 1111 FFFF FFFF 25 Largest Number Representable Byte (8-bits) 2 8-1 = 255 = FF (in hex) Halfword (16-bits) 2 16-1 = 65,535 = 64K - 1 = FFFF (in hex) Unsigned Number Representation Word (32-bits) 2 32-1 = 4,294,967,295 = 4G -1 = FFFF FFFF (in hex) 26

Two s complement number representation 8-bits Signed Number Representation Binary Hex Unsigned Value Signed Value 0000 0000 00 0 0 0000 0001 01 1 1 0000 0010 02 2 2............ 0111 1101 7D 125 125 2 7-3 0111 1110 7E 126 126 2 7-2 0111 1111 7F 127 127 2 7-1 1000 0000 80 128 1000 0001 81 129 1000 0010 82 130......... 1111 1101 FD 253 1111 1110 FE 254 1111 1111 FF 255 27 Two s complement number representation 8-bits Most significant bit 0 means " zero (in hex: 0..7) 1 means < zero (in hex: 8..F) Signed Number Representation Binary Hex Unsigned Value Signed Value 0000 0000 00 0 0 0000 0001 01 1 1 0000 0010 02 2 2............ 0111 1101 7D 125 125 2 7-3 0111 1110 7E 126 126 2 7-2 0111 1111 7F 127 127 2 7-1 1000 0000 80 128-128 -(2 7 ) 1000 0001 81 129-127 -(2 7-1) 1000 0010 82 130-126 -(2 7-2)............ 1111 1101 FD 253-3 1111 1110 FE 254-2 1111 1111 FF 255-1 28

Two s complement number representation 8-bits Most significant bit 0 means " zero (in hex: 0..7) 1 means < zero (in hex: 8..F) Signed Number Representation Binary Hex Unsigned Value Signed Value 0000 0000 00 0 0 0000 0001 01 1 1 0000 0010 02 2 2............ 0111 1101 7D 125 125 2 7-3 0111 1110 7E 126 126 2 7-2 0111 1111 7F 127 127 2 7-1 1000 0000 80 128-128 -(2 7 ) 1000 0001 81 129-127 -(2 7-1) 1000 0010 82 130-126 -(2 7-2)............ 1111 1101 FD 253-3 1111 1110 FE 254-2 1111 1111 FF 255-1 Always one more negative number than positive numbers: -128,..., -1, 0, 1,... +127 2 7 = 128 values + 2 7 = 128 values = 2 8 = 256 values 29 Two s complement number representation 32-bits Signed Number Representation Binary Hex Unsigned Value Signed Value 0000...0000 0000 0000 0 0 0000...0001 0000 0001 1 1 0000...0010 0000 0002 2 2............ 0111...1101 7FFF FFFD 2,147,483,645 2,147,483,645 2 31-3 0111...1110 7FFF FFFE 2,147,483,646 2,147,483,646 2 31-2 0111...1111 7FFF FFFF 2,147,483,647 2,147,483,647 2 31-1 1000...0000 8000 0000 2,147,483,648-2,147,483,648 -(2 31 ) 1000...0001 8000 0001 2,147,483,649-2,147,483,647 -(2 31-1) 1000...0010 8000 0002 2,147,483,650-2,147,483,646 -(2 31-1)............ 1111...1101 FFFF FFFD 4,294,967,294-3 1111...1110 FFFF FFFE 4,294,967,295-2 1111...1111 FFFF FFFF 4,294,967,296-1 Always one more negative number than positive numbers: -2,147,483,648,..., -1, 0, 1,... + 2,147,483,647 2 31 values + 2 31 values = 2 32 values 30

Ranges of Numbers Using Signed Values...in the two s complement system of number representation: Total Largest Most Number Positive Negative of Values Number Number Byte 2 8 2 7-1 -(2 7 ) (8-bits) 256 127-128 Halfword 2 16 2 15-1 -(2 15 ) (16-bits) 64K 32K-1-32K 65,536 32,767-32,768 Word 2 32 2 31-1 -(2 31 ) (32-bits) 4G 2G-1-2G 4,294,967,296 2,147,483,647-2,147,483,648 31 Addition Decimal: Binary: 1 1 1 1 1 1 3 8 5 3 1 1 1 0 1 1 0 0 + 9 3 7 4 + 1 0 1 0 1 0 1 0 1 3 2 2 7 1 1 0 0 1 0 1 1 0 0 1 2 3 4 5 6 7 8 9 10 0 0 1 2 3 4 5 6 7 8 9 10 1 1 2 3 4 5 6 7 8 9 2 2 3 4 5 6 7 8 3 3 4 5 6 7 8 4 4 5 6 7 8 5 5 6 7 8 etc. 6 6 7 7 7 8 8 9 10 0 + 0 = 0 1 + 0 = 1 1 + 1 = 10 1 + 1 + 1 = 11 32

Addition: The algorithm is the same for SIGNED and UNSIGNED. Overflow detection is slightly different. 8-bit Unsigned: 8-bit Signed: 1110 1100 = 236 1110 1100 = -20 + 1010 1010 = 170 + 1010 1010 = -86 1 1001 0110 = 406 1 1001 0110 = -106 Overflow! (max value = 255) 33 Addition: The algorithm is the same for SIGNED and UNSIGNED. Overflow detection is slightly different. 8-bit Unsigned: 8-bit Signed: 1110 1100 = 236 1110 1100 = -20 + 1010 1010 = 170 + 1010 1010 = -86 1 1001 0110 = 406 1 1001 0110 = -106 Overflow! (max value = 255) Subtraction: The algorithm is the same for SIGNED and UNSIGNED. Overflow detection is slightly different. 34

Addition: The algorithm is the same for SIGNED and UNSIGNED. Overflow detection is slightly different. 8-bit Unsigned: 8-bit Signed: 1110 1100 = 236 1110 1100 = -20 + 1010 1010 = 170 + 1010 1010 = -86 1 1001 0110 = 406 1 1001 0110 = -106 Overflow! (max value = 255) Subtraction: The algorithm is the same for SIGNED and UNSIGNED. Overflow detection is slightly different. Multiplication: Two algorithms. 8-bit Signed: 8-bit Unsigned: 1111 1110 = -2 1111 1110 = 254 X 1111 1110 = -2 X 1111 1110 = 254 0000 0000 0000 0100 = +4 1111 1100 0000 0100 = 64,516 (NOTE: Result may be twice as long as operands.) 35 Addition: The algorithm is the same for SIGNED and UNSIGNED. Overflow detection is slightly different. 8-bit Unsigned: 8-bit Signed: 1110 1100 = 236 1110 1100 = -20 + 1010 1010 = 170 + 1010 1010 = -86 1 1001 0110 = 406 1 1001 0110 = -106 Overflow! (max value = 255) Subtraction: The algorithm is the same for SIGNED and UNSIGNED. Overflow detection is slightly different. Multiplication: Two algorithms. 8-bit Signed: 8-bit Unsigned: 1111 1110 = -2 1111 1110 = 254 X 1111 1110 = -2 X 1111 1110 = 254 0000 0000 0000 0100 = +4 1111 1100 0000 0100 = 64,516 (NOTE: Result may be twice as long as operands.) Division: Two algorithms. 36

Arithmetic Negation The Algorithm to Negate a Signed Number: Bitwise complement (i.e., logical NOT) Followed by add 1 complementing: add 1: 0000 0010 = 2 37 Arithmetic Negation The Algorithm to Negate a Signed Number: Bitwise complement (i.e., logical NOT) Followed by add 1 0000 0010 = 2 complementing: 1111 1101 add 1: 38

Arithmetic Negation The Algorithm to Negate a Signed Number: Bitwise complement (i.e., logical NOT) Followed by add 1 0000 0010 = 2 complementing: 1111 1101 add 1: +0000 0001 39 Arithmetic Negation The Algorithm to Negate a Signed Number: Bitwise complement (i.e., logical NOT) Followed by add 1 0000 0010 = 2 complementing: 1111 1101 add 1: +0000 0001 1111 1110 = -2 40

Arithmetic Negation The Algorithm to Negate a Signed Number: Bitwise complement (i.e., logical NOT) Followed by add 1 0000 0010 = 2 complementing: 1111 1101 add 1: +0000 0001 1111 1110 = -2 Arithmetic negation can overflow! Every signed number can be negated,... except the most negative number. 41 Arithmetic Negation The Algorithm to Negate a Signed Number: Bitwise complement (i.e., logical NOT) Followed by add 1 0000 0010 = 2 complementing: 1111 1101 add 1: +0000 0001 1111 1110 = -2 Arithmetic negation can overflow! Every signed number can be negated,... except the most negative number. 8-Bit complementing: add 1: 1000 0000 = -128 42

Arithmetic Negation The Algorithm to Negate a Signed Number: Bitwise complement (i.e., logical NOT) Followed by add 1 0000 0010 = 2 complementing: 1111 1101 add 1: +0000 0001 1111 1110 = -2 Arithmetic negation can overflow! Every signed number can be negated,... except the most negative number. 8-Bit 1000 0000 = -128 complementing: 0111 1111 add 1: 43 Arithmetic Negation The Algorithm to Negate a Signed Number: Bitwise complement (i.e., logical NOT) Followed by add 1 0000 0010 = 2 complementing: 1111 1101 add 1: +0000 0001 1111 1110 = -2 Arithmetic negation can overflow! Every signed number can be negated,... except the most negative number. 8-Bit 1000 0000 = -128 complementing: 0111 1111 add 1: +0000 0001 44

Arithmetic Negation The Algorithm to Negate a Signed Number: Bitwise complement (i.e., logical NOT) Followed by add 1 0000 0010 = 2 complementing: 1111 1101 add 1: +0000 0001 1111 1110 = -2 Arithmetic negation can overflow! Every signed number can be negated,... except the most negative number. 8-Bit 1000 0000 = -128 complementing: 0111 1111 add 1: +0000 0001 1000 0000 = -128 45 Arithmetic Negation The Algorithm to Negate a Signed Number: Bitwise complement (i.e., logical NOT) Followed by add 1 0000 0010 = 2 complementing: 1111 1101 add 1: +0000 0001 1111 1110 = -2 Arithmetic negation can overflow! Every signed number can be negated,... except the most negative number. 8-Bit 1000 0000 = -128 complementing: 0111 1111 add 1: +0000 0001 1000 0000 = -128 The most negative 32-bit number, 0x80000000 Hex: 8 0 0 0 0 0 0 0 Binary: 1000 0000 0000 0000 0000 0000 0000 0000 Decimal: -2,147,483,648 46