CSI 333 Lecture 18 MIPS Assembly Language (MAL): Part VI (Representing Negative Integers) 18 1 / 17

Similar documents
CSI 333 Lecture 1 Number Systems

Solution for Homework 2

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

The string of digits in the binary number system represents the quantity

Useful Number Systems

Computer Science 281 Binary and Hexadecimal Review

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

HOMEWORK # 2 SOLUTIO

Lecture 2. Binary and Hexadecimal Numbers

Lecture 8: Binary Multiplication & Division

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

Number and codes in digital systems

This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers

Number Representation

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

NUMBER SYSTEMS. 1.1 Introduction

This 3-digit ASCII string could also be calculated as n = (Data[2]-0x30) +10*((Data[1]-0x30)+10*(Data[0]-0x30));

Lecture 11: Number Systems

Binary Numbers. Binary Octal Hexadecimal

Binary Adders: Half Adders and Full Adders

Systems I: Computer Organization and Architecture

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

Binary Numbering Systems

Digital Design. Assoc. Prof. Dr. Berna Örs Yalçın

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

Data Storage 3.1. Foundations of Computer Science Cengage Learning

Binary Representation

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

Numbering Systems. InThisAppendix...

Numerical Matrix Analysis

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

2011, The McGraw-Hill Companies, Inc. Chapter 3

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Data Storage. Chapter 3. Objectives. 3-1 Data Types. Data Inside the Computer. After studying this chapter, students should be able to:

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

Arithmetic in MIPS. Objectives. Instruction. Integer arithmetic. After completing this lab you will:

CPEN Digital Logic Design Binary Systems

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

Math 115 Spring 2011 Written Homework 5 Solutions

DATA_TYPE Values and Data File Storage Formats

Measures of Error: for exact x and approximation x Absolute error e = x x. Relative error r = (x x )/x.

Goals. Unary Numbers. Decimal Numbers. 3,148 is s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1

Review of Scientific Notation and Significant Figures

3. Convert a number from one number system to another

CS201: Architecture and Assembly Language

Q-Format number representation. Lecture 5 Fixed Point vs Floating Point. How to store Q30 number to 16-bit memory? Q-format notation.

Recall the process used for adding decimal numbers. 1. Place the numbers to be added in vertical format, aligning the decimal points.

Chapter 2. Binary Values and Number Systems

Karnaugh Maps & Combinational Logic Design. ECE 152A Winter 2012

CHAPTER 5 Round-off errors

The New IoT Standard: Any App for Any Device Using Any Data Format. Mike Weiner Product Manager, Omega DevCloud KORE Telematics

Chapter 7D The Java Virtual Machine

Attention: This material is copyright Chris Hecker. All rights reserved.

Digital to Analog and Analog to Digital Conversion

Number Conversions Dr. Sarita Agarwal (Acharya Narendra Dev College,University of Delhi)

DNA Data and Program Representation. Alexandre David

( 214 (represen ed by flipping) (magnitude = -42) = = -42 (flip the bits and add 1)

The programming language C. sws1 1

Byte Ordering of Multibyte Data Items

EE361: Digital Computer Organization Course Syllabus

1. Convert the following base 10 numbers into 8-bit 2 s complement notation 0, -1, -12

The Answer to the 14 Most Frequently Asked Modbus Questions

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

Floating point package user s guide By David Bishop (dbishop@vhdl.org)

NAND Flash Memories. Using Linux MTD compatible mode. on ELNEC Universal Device Programmers. (Quick Guide)

Introduction to Xilinx System Generator Part II. Evan Everett and Michael Wu ELEC Spring 2013

AN617. Fixed Point Routines FIXED POINT ARITHMETIC INTRODUCTION. Thi d t t d ith F M k Design Consultant

BINARY CODED DECIMAL: B.C.D.

Pemrograman Dasar. Basic Elements Of Java

Correctly Rounded Floating-point Binary-to-Decimal and Decimal-to-Binary Conversion Routines in Standard ML. By Prashanth Tilleti

Verilog - Representation of Number Literals

Instruction Set Architecture (ISA)

Computer Architecture. Secure communication and encryption.

Implementation of Modified Booth Algorithm (Radix 4) and its Comparison with Booth Algorithm (Radix-2)

CS321. Introduction to Numerical Methods

Z80 Instruction Set. Z80 Assembly Language

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

MACHINE INSTRUCTIONS AND PROGRAMS

Fractions and Linear Equations

INTERNATIONAL TELECOMMUNICATION UNION

Unsigned Conversions from Decimal or to Decimal and other Number Systems

Number of bits needed to address hosts 8

Faculty of Engineering Student Number:

Agilent Technologies. Signal Generators. Creating and Downloading Waveform Files. E448C ESG RF E8267D PSG Microwave N5162A/82A MXG RF

Session 29 Scientific Notation and Laws of Exponents. If you have ever taken a Chemistry class, you may have encountered the following numbers:

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Chapter 5 Instructor's Manual

Streaming Lossless Data Compression Algorithm (SLDC)

A White Paper about. MiniSEED for LISS and data compression using Steim1 and Steim2

Positional Numbering System

6.1 The Greatest Common Factor; Factoring by Grouping

NUMBER SYSTEMS. William Stallings

Transcription:

CSI 333 Lecture 18 MIPS Assembly Language (MAL): Part VI (Representing Negative Integers) 18 1 / 17

Representing Negative Integers Ref: Section 2.4 of Patterson & Hennessey text. Numbering of Bits: 0 1 2 n 1 n... Big Endian MSB LSB n n 1 2 1 0... Little Endian MSB Word size = n+1 bits LSB Notes: We will assume Little Endian bit numbering. The most significant bit is the sign bit (0 for non-negative, 1 for negative). 18 2 / 17

Representing Negative Integers (continued) Known Methods: Sign Magnitude representation. (Not common) One s complement representation. (Not common) Two s complement representation. (Common) Biased representation. (Used in special situations) 18 3 / 17

Sign Magnitude Form Example: (with word size n + 1 = 8 bits) 00101000 -- represents +40 10101000 -- represents -40 Range: For a word size of n + 1, Smallest integer = (2 n 1) Largest integer = +(2 n 1) Example: With n + 1 = 8, the range of integers representable using sign-magnitude form is 127 through +127. 18 4 / 17

Sign Magnitude Form (continued) Formula for value: Bit string : b n b n 1... b 1 b 0 n 1 Value : ( 1) bn b i 2 i i=0 Disadvantage: The integer zero has two representations: 00000000 -- represents +0 10000000 -- represents -0 18 5 / 17

One s Complement Form Positive integers: sign bit = 0. Usual binary representation with Negative integers: Complement the binary representation of the corresponding positive value. (The sign bit is also complemented.) Example: 0 0 0 0 1 1 1 1 -- represents +15 1 1 1 1 0 0 0 0 -- represents -15 Problem: What decimal value does the 1 s complement binary number 10010010 represent? Solution: When we complement all the bits, we get 01101101, which represents +109 decimal. So, the given integer = 109. 18 6 / 17

One s Complement Form (continued) Range: For a word size of n + 1, Smallest integer = (2 n 1) Largest integer = +(2 n 1) Example: With n + 1 = 8, the range of integers representable using 1 s complement form is 127 through +127. Formula for value: Disadvantage: Bit string : b n b n 1... b 1 b 0 Value : n 1 b i 2 i b n (2 n 1) i=0 The integer zero has two representations: 00000000 -- represents +0 11111111 -- represents -0 18 7 / 17

Two s Complement Form Positive integers: Usual binary representation, with sign bit = 0. Negative integers: Take 1 s complement and then add 1. Recall: Binary addition table. Inputs Sum Carry ------ --- ----- 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 1 18 8 / 17

Two s Complement Form (continued) Problem: Find the 2 s complement representation of 15 using 8 bits. Solution: +15: 0 0 0 0 1 1 1 1 1 s compl.: 1 1 1 1 0 0 0 0 Add 1 : 1 --------------- 1 1 1 1 0 0 0 1 <-- Answer 18 9 / 17

Two s Complement Form (continued) Problem: Solution: Find the 2 s complement representation of 64 using 8 bits. +64: 0 1 0 0 0 0 0 0 1 s compl.: 1 0 1 1 1 1 1 1 Add 1 : 1 1 1 1 1 1 1 <-- Carries --------------- 1 1 0 0 0 0 0 0 <-- Answer Another method for 2 s complement: 1 Start with the binary representation of the positive value. 2 Copy bits from right to left, until the first 1 has been copied. 3 Complement every bit thereafter. 18 10 / 17

Two s Complement Form (continued) Problem: Solution: Find the 2 s complement representation of 64 using 8 bits. +64: 0 1 0 0 0 0 0 0 2 s complement representation for -64: 1 1 0 0 0 0 0 0 ^ (First 1 copied) Problem: What decimal value does the 2 s complement binary number 11111111 represent? Solution: When we take the 2 s complement of the given number, we get 00000001, which represents +1 decimal. So, the given integer = 1 decimal. 18 11 / 17

Two s Complement Form (continued) Problem: What is the 2 s complement of 00000000? Solution: Given: 0 0 0 0 0 0 0 0 1 s compl.: 1 1 1 1 1 1 1 1 Add 1 : 1 1 1 1 1 1 1 1 <-- Carries --------------- 0 0 0 0 0 0 0 0 <-- Answer (value = 0) 1 --> Carry out of sign bit (must be ignored) So, zero has a unique representation in 2 s complement form. Note: In 2 s complement arithmetic, the carry out of the sign bit is called the end around carry. It should be ignored. (It does not indicate overflow.) 18 12 / 17

Two s Complement Form (continued) Range: For a word size of n + 1, Smallest integer = 2 n Largest integer = +(2 n 1) For example, with n + 1 = 8, the range of integers representable using 2 s complement form is 128 through +127. (The range is asymmetric.) Formula for value: Bit string : b n b n 1... b 1 b 0 Value : n 1 b i 2 i b n 2 n i=0 18 13 / 17

Two s Complement Form (continued) A (minor) disadvantage: Because of the asymmetry of the range, we cannot take the 2 s complement of the smallest (i.e., most negative) value. Example: The 2 s complement representation for 128 decimal using 8 bits is 10000000. (Verify this.) When we take the 2 s complement of 10000000, we get 10000000 itself, which is incorrect. Reason: The expected result, namely +128, cannot be represented using 8 bits (including the sign bit). 18 14 / 17

Biased Representation Used only in special situations. No sign bit (i.e., the resulting representation is unsigned). A suitable positive integer B is chosen as the bias. Integer i (positive or negative) is represented by the unsigned binary representation of the value B + i. Examples: Consider 8-bit representations with bias = 127. 1 Biased-127 representation of the decimal value +9 is the 8-bit unsigned representation of the integer 127 + 9 = 136, namely 10001000. 2 Biased-127 representation of the decimal value 21 is the 8-bit unsigned representation of the integer 127 21 = 106, namely 01101010. 18 15 / 17

Biased Representation (continued) Range: For a word size of n + 1 and bias B Smallest integer = B Largest integer = +(2 n+1 1 B) Example: With n + 1 = 8 and bias B = 127, the range of integers representable using Biased-127 form is 127 through +128. (The range is asymmetric.) Formula for value: Bit string : b n b n 1... b 1 b 0 Bias : Value : B n b i 2 i B i=0 18 16 / 17

Biased Representation (continued) Notes: Used to store the exponents in the IEEE Floating Point Standard (IEEE FPS) representation. For a word size of n + 1 bits, the normally chosen bias values are either 2 n or 2 n 1. (Reason: This keeps the range of values reasonably symmetric around zero.) 18 17 / 17