M68K Assembly Language Programming Bob Britton Chapter 4 Number Systems.

Slides:



Advertisements
Similar presentations
Intro to CS – Honors I Representing Numbers GEORGIOS PORTOKALIDIS
Advertisements

Representing Numbers: Integers
HEXADECIMAL NUMBERS Code
Company LOGO Edit your slogan here DKT 122/3 DIGITAL SYSTEM 1 WEEK #3 NUMBER SYSTEMS, OPERATION & CODES (PART 2)
Chapter 2 : Number System
Digital Fundamentals Floyd Chapter 2 Tenth Edition
Data Representation Computer Organization &
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Data Representation COE 205
Assembly Language and Computer Architecture Using C++ and Java
Assembly Language and Computer Architecture Using C++ and Java
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
Chapter Chapter Goals Know the different types of numbers Describe positional notation.
VIT UNIVERSITY1 ECE 103 DIGITAL LOGIC DESIGN CHAPTER I NUMBER SYSTEMS AND CODES Reference: M. Morris Mano & Michael D. Ciletti, "Digital Design", Fourth.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems.
Number System and Codes
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
The M68HC11 Basic Instruction Set Basic Arithmetic Instructions
Dr. Bernard Chen Ph.D. University of Central Arkansas
Binary Representation - Shortcuts n Negation x + x = 1111…1111 two = -1 (in 2’s complement) Therefore, -x = x + 1 n Sign Extension o Positive numbers :
Simple Data Type Representation and conversion of numbers
ES 244: Digital Logic Design Chapter 1 Chapter 1: Introduction Uchechukwu Ofoegbu Temple University.
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
Data Representation – Binary Numbers
Computers Organization & Assembly Language
The 8051 Microcontroller and Embedded Systems
CMPE 325 Computer Architecture II Cem Ergün Eastern Mediterranean University Integer Representation and the ALU.
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
Binary Arithmetic & Data representation
1 Digital Systems and Binary Numbers EE 208 – Logic Design Chapter 1 Sohaib Majzoub.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
ECEN2102 Digital Logic Design Lecture 1 Numbers Systems Abdullah Said Alkalbani University of Buraimi.
1.11, 1.12, 1.13, 1.14, 1.18, 1.20, 1.23, 1.24, 1.25, 1.32, 1.33.
Digital Logic Design Lecture 3 Complements, Number Codes and Registers.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
Number systems, Operations, and Codes
The Hexadecimal Number System and Memory Addressing ISAT 121.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Operations on Bits Arithmetic Operations Logic Operations
EEL 3801C EEL 3801 Part I Computing Basics. EEL 3801C Data Representation Digital computers are binary in nature. They operate only on 0’s and 1’s. Everything.
Computer Math CPS120 Introduction to Computer Science Lecture 4.
Addition and Substraction
Introduction to Microprocessors Chapter 2. Decimal or Base 10 Numbers  Have ten different digits (0-9)  It is a weighted number system. Each position.
SAK Chapter 21 Chapter 2 : Number System 2.1 Decimal, Binary, Octal and Hexadecimal Numbers 2.2 Relation between binary number system with other.
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
Introduction To Number Systems Binary System M. AL-Towaileb1.
IT1004: Data Representation and Organization Negative number representation.
CHAPTER 3 Arithmetic For Computers 1/31/ Topics for discussion 1/31/ Number system: { radix/base, a set of distinct digits, operations} Radix.
CCE Department – Faculty of engineering - Islamic University of Lebanon Chapter 6 Binary Arithmetic.
Integer Operations Computer Organization and Assembly Language: Module 5.
MicroProcessors Lec. 4 Dr. Tamer Samy Gaafar. Course Web Page —
Computer Math CPS120 Introduction to Computer Science Lecture 7.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
11001 / 101, / ) Perform subtraction on the given unsigned binary numbers using the 2's complement of the subtrahend. Where the result.
Cosc 2150: Computer Organization
Number Systems and Codes
NUMBER SYSTEMS.
Lec 3: Data Representation
Data Representation.
11001 / 101 , / ) Perform subtraction on the given unsigned binary numbers using the 2's complement of the subtrahend. Where the.
Chapter 3 Data Representation
Number Systems.
Number Systems and Binary Arithmetic
Number Systems and Codes
Computer Architecture & Operations I
ECE 331 – Digital System Design
CS334: Number Systems Lab 1.
Introduction To Number Systems
Presentation transcript:

M68K Assembly Language Programming Bob Britton Chapter 4 Number Systems

Introduction Polynomial Expansion Binary Numbers Hexadecimal Numbers Two’s Complement Number System Arithmetic & Overflow Detection American Standard Code for Information Interchange (ASCII)

Polynomial Expansion of a Decimal Number (Base 10) 496 = 4 x x x 10 Polynomial Expansion of a Binary Number (Base 2) = 1 x x x x x 2 + 1x A Faster Method Double and Add = 45 (1, 2, 5, 11, 22, 45)

Conversion of Decimal Numbers to Binary Divide by 2 and extract the remainder 45 Remainder

Practice - Convert 25 to Binary Divide by 2 and record the remainder 25 Remainder 12

To represent binary values in the positive and negative domains we use the Two’s Complement Number System Here is the polynomial expansion of a two’s complement 8-bit binary number N: N = - d 7 x2 + d 6 x2 + d 5 x2 + d 4 x2 + d 3 x2 + d 2 x2 + d 1 x2 +d 0 x2 Notice the Minus sign *** You need to memorize powers of 2 ***

The Two’s Complement Operation When we take the two’s complement of a binary number, the result will be the negative of the value we started with. For example, the binary value is 26 in decimal. To find the value negative 26 (-26) in binary we perform the two’s complement operation on Scan the binary number from right to left leaving all least significant zeros (0) and the first one (1) unchanged, and then complementing the remaining digits to the left: The result is the value negative 26 (-26) in binary.

Binary Arithmetic & Overflow Detection in the Two’s Complement Number System Here is an addition example where we assume we are limited to 8 binary digits = = = -128 Overflow Occurred

Overflow

Binary Arithmetic in the Two’s Complement Number System Here is a subtraction example where we assume we are limited to 8 binary digits. To subtract in binary we always add the two’s complement of the subtrahend = = = = 8

The Rule for Detection of Overflow ################################################# Adding numbers of opposite signs, overflow is impossible. When adding numbers of the same sign, if the result is not the same as the operands then overflow occurred. ################################################# Here is an example: You are given the following two numbers in two’s complement representation. Perform the binary subtraction and indicate if there is signed overflow. ______ Explain Why: = = Correct Result = -43

Sign Extension The value – 43 as an 8-bit binary number is: The value – 43 as an 32-bit binary number is: In Hexadecimal – 43 appears as: 0xFFFFFFD5 ############################################### The value 68 as an 8-bit binary number is: The value 68 as an 32-bit binary number is: In Hexadecimal 68 appears as: 0x

The Hexadecimal Number System DecimalHexBinary A B C D E F1111 Here is an example of how we compactly represent binary numbers in hexadecimal: | | | | | $ 3 C 8 F 7 E

Multiplication by constants that are a Power of 2 is accomplished much more efficiently using the Arithmetic Shift Left instruction*. ASL.L#3, D0* D0*8 --> D0 bvsoverflow *See Appendix B for a description of the ASL instruction

Division by constants that are a Power of 2 is accomplished much more efficiently using the Arithmetic Shift Right instruction ASR.L#1, D0* D0/2 --> D0 *See Appendix B for a description of the ASR instruction

MIPS Assembly Language Programming Bob Britton Chapter 4 Exercises Number Systems

Exercises 4.1Convert the decimal number 35 to an 8-bit binary number. 4.2Convert the decimal number 32 to an 8-bit binary number. 4.3Using the double and add method convert to a decimal number. 4.4Using the double and add method convert to a decimal number. 4.5Explain why the Least Significant digit of a binary number indicates if the number is odd or even. 4.6Convert the binary number to a hexadecimal number. 4.7Convert the binary number to a hexadecimal number. 4.8Convert the hexadecimal number $15 to a decimal number. 4.9Convert the hexadecimal number $19 to a decimal number. 4.10Convert the decimal number -35 to an 8-bit two’s complement binary number LSD is a 1 $15 $

Exercises 4.11Convert the decimal number -32 to an 8-bit two’s complement binary number. 4.12Assuming the use of the two’s complement number system find the equivalent decimal values for the following 8-bit binary numbers: (a) (b) (c) (d) (e) Convert the base 8 number 204 to decimal 4.14Convert the base 7 number 204 to decimal 4.15Convert the base 6 number 204 to decimal 4.16Convert the base 5 number 204 to decimal 4.17Convert the base 10 number 81 to a base 9 number

Exercises 4.18For each row of the table below convert the given 16 bit number to each of the other two bases, assuming the two’s complement number system is used. 16 Bit BinaryHexadecimalDecimal $FF $ You are given the following two numbers in two’s complement representation. Perform the binary addition and indicate if there is signed overflow. __ Explain Why: Yes overflow occurred – Sign of the result is different from the operands

Exercises 4.21You are given the following two numbers in two’s complement representation. Perform the binary subtraction and indicate if there is signed overflow. ______ Explain Why: 4.22Sign extend the 8 bit hex number $88 to a 16 bit number. $_________ 4.23The first subtract instruction is located at address $ What are the two possible values for the contents of the PC after the branch instruction is executed? $_____________$ ____________ loop:sub#8, D4 subD4, D2 bneloop No Overflow FF

Exercises 4.24You are given the following two 8-bit binary numbers in the two’s complement number system. What values do they represent in decimal? X = = __________Y = = __________ Perform the following arithmetic operations on X and Y. Show your answers as 8-bit binary numbers in the two’s complement number system. To subtract Y from X, find the two’s complement of Y and add it to X. Indicate if overflow occurs in performing any of these operations. X+YX-YY-X

Exercise 4.25 The following code segment is stored in memory starting at memory location $ What are the two possible values for the contents of the PC after the branch instruction has executed? $__________ $ ____________ Add in line pseudocode to describe each instruction. loop:move(A0), D0* adda#4, A0* and#1, D0* beqloop * D0 = Mem[A0] A0 = A0 + 4 D0 = D0 & 1 “Extract LSD” if D0 is an even # go to loop

Example Quiz You are given the following two 8 bit binary numbers in the two’s complement number system. What values do they represent in decimal? X= = 2 Y= = 2 Perform the following arithmetic operations on X and Y. Show your answers as 8 bit binary numbers in the two’s complement number system. To subtract Y from X find the two’s complement of Y and add it to X. Indicate if overflow occurs in performing any of these operations. X+YX-YY-X

Beginning of the PrintHex Function ######################################## # Algorithmic Description in Pseudo Code: # #########################################.globlPrintHex.data buffer:.asciiz" 0x ".text PrintHex: la$a1, buffer addi$a1, $a1, 10# Set pointer to end of buffer......# Body of the Algorithm... jr$ra