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



Similar documents
Computer Science 281 Binary and Hexadecimal Review

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

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

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

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

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

Solution for Homework 2

Data Storage 3.1. Foundations of Computer Science Cengage Learning

Lecture 2. Binary and Hexadecimal Numbers

Systems I: Computer Organization and Architecture

HOMEWORK # 2 SOLUTIO

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

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

CS321. Introduction to Numerical Methods

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

Number Representation

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

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

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

The Answer to the 14 Most Frequently Asked Modbus Questions

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

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

CSI 333 Lecture 1 Number Systems

Lecture 11: Number Systems

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

Numbering Systems. InThisAppendix...

CPEN Digital Logic Design Binary Systems

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

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

CHAPTER 5 Round-off errors

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

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

Binary Numbers. Binary Octal Hexadecimal

DNA Data and Program Representation. Alexandre David

Useful Number Systems

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

Chapter 4: Computer Codes

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

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

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

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

Base Conversion written by Cathy Saxton

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

Binary Numbering Systems

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

Digital to Analog and Analog to Digital Conversion

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

The Hexadecimal Number System and Memory Addressing

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

Binary Adders: Half Adders and Full Adders

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

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

Numerical Matrix Analysis

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

Binary Representation

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

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

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

CS201: Architecture and Assembly Language

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

Zuse's Z3 Square Root Algorithm Talk given at Fall meeting of the Ohio Section of the MAA October College of Wooster

Chapter 2. Binary Values and Number Systems

First Bytes Programming Lab 2

Informatica e Sistemi in Tempo Reale

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

BCD (ASCII) Arithmetic. Where and Why is BCD used? Packed BCD, ASCII, Unpacked BCD. BCD Adjustment Instructions AAA. Example

Chapter Binary, Octal, Decimal, and Hexadecimal Calculations

NUMBER SYSTEMS. 1.1 Introduction

The programming language C. sws1 1

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

Lecture N -1- PHYS Microcontrollers

CALCULATIONS & STATISTICS

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

THE BINARY NUMBER SYSTEM

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

BINARY CODED DECIMAL: B.C.D.

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

ASCII Characters. 146 CHAPTER 3 Information Representation. The sign bit is 1, so the number is negative. Converting to decimal gives

COMPSCI 210. Binary Fractions. Agenda & Reading

Technical Support Bulletin Nr.18 Modbus Tips

Number Systems and Radix Conversion

Section 3. Sensor to ADC Design Example

2003 HSC Notes from the Marking Centre Software Design and Development

The BBP Algorithm for Pi

Formatting Numbers with C++ Output Streams

1.Eastron SDM220Modbus Smart Meter Modbus Protocol Implementation V1.0

THE EXACT DOT PRODUCT AS BASIC TOOL FOR LONG INTERVAL ARITHMETIC

Data Storage: Each time you create a variable in memory, a certain amount of memory is allocated for that variable based on its data type (or class).

Section 1.4 Place Value Systems of Numeration in Other Bases

M6800. Assembly Language Programming

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

Chapter 1: Digital Systems and Binary Numbers

Decimal to Binary Conversion

Traditional IBM Mainframe Operating Principles

Decimal form. Fw.d Exponential form Ew.d Ew.dEe Scientific form ESw.d ESw.dEe Engineering form ENw.d ENw.dEe Lw. Horizontal

This section describes how LabVIEW stores data in memory for controls, indicators, wires, and other objects.

Transcription:

Introduction to Embedded Microcomputer Systems Lecture 5.1 2.9. Conversions ASCII to binary n = 100*(Data[0]-0x30) + 10*(Data[1]-0x30) + (Data[2]-0x30); This 3-digit ASCII string could also be calculated as n = (Data[2]-0x30) +10*((Data[1]-0x30)+10*(Data[0]-0x30)); binary to ASCII Assume n is an unsigned integer less than or equal to 999: Data[0] = n/100 + 0x30; n = n%100; /* 0 and 99 */ Data[1] = n/10 + 0x30; n = n%10; /* 0 and 9 */ Data[2] = n + 0x30; 2.10. Fixed-point numbers Why: express values with noninteger values no floating point hardware support When: range of values is known range of values is small How: 1) variable integer, called I. may be signed or unsigned

Introduction to Embedded Microcomputer Systems Lecture 5.2 may be 8, 16 or 32 bits (precision) 2) fixed constant, called D (resolution) value is fixed, and can not be changed not stored in memory specify this fixed content using comments The value of the fixed-point number fixed-point number I D decimal fixed-point, D=10 m decimal fixed-point number = I 10 m nice for human input/output binary fixed-point, D=2 m binary fixed-point number = I 2 m easier for computers to perform calculations Checkpoint 2.46: Give an approximation of π using the decimal fixed-point ( = 0.001) format. Analog to digital converter (ADC) analog input range is 0 to +5 V, digital output varies 0 to 255 Vin = 5*N/255 = 0.019607843*N

Introduction to Embedded Microcomputer Systems Lecture 5.3 Decimal fixed-point is chosen because the voltage data for this voltmeter will be displayed. A fixed-point resolution of =0.01 V is chosen because it is slightly smaller (better) than the ADC resolution. Vin (V) N I (10 mv) LCD Analog in digital out variable part 0 0 0 0.00 0.02 1 2 0.02 1 51 100 1.00 2.5 128 250 2.50 5 255 500 5.00 Table 2.22. Performance data of voltmeter. The software performs the following fixed-point calculation to convert N into I. Vin = 5 N/255 how ADC works Vin = I 0.01 definition of fixed point I = (5 100*N)/255 substitution I = (100 N)/51 simplify I = (100 N+25)/51 round to closest integer There are two mistakes that can happen. Overflow result exceeds the range of number system promotion and ceiling/floor. Drop-out occurs after an integer right shift or a divide intermediate result looses the information divide last when performing multiple calculations

Introduction to Embedded Microcomputer Systems Lecture 5.4 100 (N/51)? (100 N)/51 Let x,y,z be three fixed-point numbers with same D x=i D, y=j D, and z=k D. To perform addition z=x+y, K=I+J To perform subtraction z=x-y, K=I-J Let x,y,z be three fixed-point numbers with different D x=i 2-5, y=j 2-2, and z=k 2-3. To perform addition z=x+y, first convert to common K=I/4+2 J For multiplication, we have z=x y. Let x,y,z be three fixed-point numbers with different D x=i 2 n, y=j 2 m, and z=k 2 p. K 2 p =I 2 n J 2 m K =I J 2 n+m-p For division, we have z=x/y. K 2 p = (I 2 n )/(J 2 m ) K =I/J 2 n-m-p depends on if (n-m-p)>0 We must worry about overflow and drop out.

Introduction to Embedded Microcomputer Systems Lecture 5.5 Consider the following digital filter calculation. y = x -0.0532672 x 1 + x 2 + 0.0506038 y 1-0.9025 y 2 The variables y, y 1, y 2, x, x 1, and x 2 are all integers -0.0532672-14 2-8 0.0506038 13 2-8 -0.9025-231 2-8 y = x + x 2 + (-14 x 1 +13 y 1-231 y 2 )>>8 Common Error: Lazy or incompetent programmers use floating-point in many situations where fixed-point would be preferable. Observation: As the fixed constant is made smaller, the accuracy of the fixed-point representation is improved, but the variable integer part also increases. Unfortunately, larger integers will require more bits for storage and calculations. 2.11. *Floating-point numbers Observation: If the range of numbers is unknown or large, then the numbers must be represented in a floating-point format. Observation: Floating-point implementations on computers like the 6811/6812 that do not have hardware support are extremely long and very slow. So, if you really need

Introduction to Embedded Microcomputer Systems Lecture 5.6 floating point, a computer with hardware support is highly desirable. The floating-point format, f, for short real data type Bit 31 Mantissa sign, s=0 for positive, s=1 for negative Bits 30:23 8-bit biased binary exponent 0 = e = 255 Bits 22:0 24-bit mantissa, m, expressed as a binary fraction, a binary 1 as the most significant bit is implied. m = 1.m 1 m 2 m 3...m 23 s e 7 e 0 m 1 m 23 Figure 2.36. 32-bit short real floating-point format. The value of a short real floating-point number is f = (-1) s 2 e-127 m The range of values is about ±10-38 to ±10 +38. A precision of about 7 decimal digits. Short real floating point representation of 0.1 Step 1 0.1 = (-1) 0 0.1 Step 2, 0.1 = (-1) 0 2-4 1.6 Step 3 0.1 = (-1) 0 2 123-127 1.6 Step 4 0.1 = (-1) 0 2 123-127 (1+0.6) Step 5 0.1 (-1) 0 2 123-127 (1+5033165 2-23 ) Step 6 0.1 (-1) 0 2 $7B-127 (1+$4CCCCD 2-23 ) Step 7 0.1 (0,$7B,$4CCCCD) = (0,01111011,10011001100110011001101)

Introduction to Embedded Microcomputer Systems Lecture 5.7 The following example shows the steps in finding the floating point approximation for π. Step 1 π = (-1) 0 π Step 2, π (-1) 0 2 1 1.570796327 Step 3 π (-1) 0 2 128-127 1.570796327 Step 4 π (-1) 0 2 128-127 (1+0.570796327) Step 5 π (-1) 0 2 128-127 (1+4788187 2-23 ) Step 6 π (-1) 0 2 $80-127 (1+$490FDB 2-23 ) Step 7 π (0,$80,$490FDB) = (0,10000000,10010010000111111011011) When e is 255, plus or minus infinity When e is 0, denormalized f = (-1)s 2-126 m where m = 0.m 1 m 2 m 3...m 23 Roundoff is the error that occurs as a result of an arithmetic operation. discarding the least significant bits of the product multiplication of two 64-bit mantissas yields a 128-bit product. The final result is normalized into a normalized floating point number with a 64-bit mantissa. Roundoff during addition and subtraction error results when smaller number is shifted right two n-bit numbers are added the result is n+1 bits

Introduction to Embedded Microcomputer Systems Lecture 5.8 Truncation is the error that when a number is converted from one format to another. For example, 0.1 could not be exactly represented 2.12. Tutorial 2. Arithmetic and logical operations format descriptions examples h 8-bit unsigned hexadecimal $00 $12 $FF d 8-bit unsigned decimal 0 18 255 b 8-bit unsigned binary %00000000 %00010010 H 16-bit unsigned hexadecimal $0000 $1234 $FFFF D 16-bit unsigned decimal 0 4660 65535 B 16-bit unsigned binary %0001001000110100 -h or +h 8-bit signed hexadecimal -$80 +$12 +$7F -d or +d 8-bit signed decimal -128 +18 +127 -b or +b 8-bit signed binary -%10000000 +%00010010 -H or +H 16-bit signed hexadecimal -$8000 +$1234 +$7FFF -D or +D 16-bit signed decimal -32768 +4660 +32767 -B or +B 16-bit signed binary -+%0001001000110100 b3 3-bit binary (lsb) %000 %111 b4 4-bit binary (lsb) %0000 %1111 cc 8-bit binary CCR sxhinzvc c or C ASCII character 'A' 'x' '0' s or S ASCII string "Hello World" v address itself, unsigned dec 2048 V address itself, unsigned hex $0800 +v or v address itself, signed dec -32768 +0 +32767 +V or V address itself, signed hex -$8000 +0 +$7FFF Table 2.23. Available formats for displaying ViewBox. Action. Execute TExaS and open the Chap2.rtf and Chap2.uc files. Bring the ViewBox to the front. We will begin talking about unsigned numbers, so we will use the d format

Introduction to Embedded Microcomputer Systems Lecture 5.9 to observe values in Register A, and use the D format for Register X. Question 2.1. Register A contains an 8-bit integer. Its precision is 8 bits. As an unsigned number, its range of values is 0 to 255. What happens when you try to set Register A to 256? Question 2.2. What happens when you try to set Register A to - 1? Question 2.3. Register X contains a 16-bit integer. Its precision is 16 bits. As an unsigned number, its range of values is 0 to 65535. What happens when you try to set Register X to 65536? Question 2.4. What happens when you try to set Register X to - 1? Action. Next, we will study signed numbers. Change the format of Register A to the +d, and change the format of Register X to the +D. To change the format of a parameter in the ViewBox: click on the ViewBox entry, type the new format in the Format field, then hit enter. Question 2.5. As a signed number, the range of values in Register A is -128 to +127. What happens when you try to set Register A to +128? Question 2.6. What happens when you try to set Register A to - 129?

Introduction to Embedded Microcomputer Systems Lecture 5.10 Question 2.7. As a signed number, the range of values in Register X is -32768 to +32767.What happens when you try to set Register X to 32768? Question 2.8. What happens when you try to set Register X to - 32769? Question 2.9: Use the help system of TExaS to look up the instruction ldaa and answer the question, Even though the ldaa instruction does not perform any arithmetic or logical operations, does it modify the condition code bits, N, Z, V, and C? Within the TExaS application execute Help->HelpTopics, double click 6812 assembly language, double-click 6812 memory access instructions, click ldaa. Action. Assemble the Chap2.rtf program, and bring the TheList.rtf TheLog.rtf and Chap2.uc windows to the front. Notice that the instructions lsla and asla have the same object code. Question 2.10: First perform the following logical operations by hand, and record what you think the result will be in 8-bit unsigned hexadecimal. In addition, record your expectation for the N and Z bits. Within TExaS, change the format of Register A to unsigned hexadecimal h. Reset and single-step the program through part 1. Correct your answers by recording the proper values of Register A and the CCR bits N and Z. The logical operations clear the V bit. The complement instruction is the only one that sets the C bit, while the other logical operations only affect the N Z and V bits.

Introduction to Embedded Microcomputer Systems Lecture 5.11 $0F&$85 $0F $85 $0F^$85 ~$0F Question 2.11: First perform the following unsigned arithmetic operations by hand, and record what you think the result will be in 8-bit unsigned decimal format. In addition, record your expectation for the N Z and C bits. Although the processor will set the V bit during the calculation, we will ignore it when operating on unsigned integers. Within TExaS, change the format of Register A to unsigned decimal d. Single-step the program through part 2. Correct your answers by recording the proper values of Register A and the CCR bits N Z and C. 155>>1 50<<1 96+64 224+64 160-64 32-64 Question 2.12: First perform the following signed arithmetic operations by hand, and record what you think the result will be in 8-bit signed decimal. In addition, record your expectation for the N Z and V bits. Although the processor will set the C bit during the calculation, we will ignore it when operating on signed integers. Within TExaS, change the format of Register A to signed decimal +d. Single-step the program through part 3. Correct your answers by recording the proper values of Register A and the CCR bits N Z and V. -101>>1

Introduction to Embedded Microcomputer Systems Lecture 5.12-50<<1-32+64 96+64 32-64 -96-64