Summary. Description. Mosaic Industries. Conversion of HEX ASCII Floating Point Number to Binary IEEE Format APPLICATION NOTE MI-AN-050

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

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

M6800. Assembly Language Programming

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

Programming the Motorola MC68HC11 Microcontroller

The stack and the stack pointer

Lecture 3 Addressing Modes, Instruction Samples, Machine Code, Instruction Execution Cycle

HC12 Assembly Language Programming

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

Number Representation

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

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

Caml Virtual Machine File & data formats Document version: 1.4

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

Systems I: Computer Organization and Architecture

Microcontroller Basics A microcontroller is a small, low-cost computer-on-a-chip which usually includes:

Programming languages C

Application Note. Introduction AN2471/D 3/2003. PC Master Software Communication Protocol Specification

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

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

DNA Data and Program Representation. Alexandre David

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

Motorola 8- and 16-bit Embedded Application Binary Interface (M8/16EABI)

Programmer s Model = model of µc useful to view hardware during execution of software instructions

HOMEWORK # 2 SOLUTIO

Chapter 7D The Java Virtual Machine

The Answer to the 14 Most Frequently Asked Modbus Questions

Numbering Systems. InThisAppendix...

Numerical Matrix Analysis

Solution for Homework 2

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

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

Data Storage 3.1. Foundations of Computer Science Cengage Learning

Computer Science 281 Binary and Hexadecimal Review

Version 4 MAT-File Format

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

Hexadecimal Object File Format Specification

How To Write Portable Programs In C

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

Application Note AN0008. Data Logging Extension. For. Venus 8 GPS Receiver

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

RS-485 Protocol Manual

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

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

Ecma/TC39/2013/NN. 4 th Draft ECMA-XXX. 1 st Edition / July The JSON Data Interchange Format. Reference number ECMA-123:2009

The programming language C. sws1 1

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

Chapter 4: Computer Codes

Interrupts and the Timer Overflow Interrupts Huang Sections What Happens When You Reset the HCS12?

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

Intel Hexadecimal Object File Format Specification Revision A, 1/6/88

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

Technical Support Bulletin Nr.18 Modbus Tips

Lecture 2. Binary and Hexadecimal Numbers

Thermistor Calculator. Features. General Description. Input/Output Connections. When to use a Thermistor Calculator 1.10

PROBLEMS (Cap. 4 - Istruzioni macchina)

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

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

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

The Hexadecimal Number System and Memory Addressing

Stacks. Linear data structures

Monday January 19th 2015 Title: "Transmathematics - a survey of recent results on division by zero" Facilitator: TheNumberNullity / James Anderson, UK

An overview of FAT12

Call Subroutine (PC<15:0>) TOS, (W15)+2 W15 (PC<23:16>) TOS, Process data. Write to PC NOP NOP NOP NOP

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

Keil C51 Cross Compiler

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

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

TMS320C67x FastRTS Library Programmer s Reference

Embedded system programming: HCS12

CSI 333 Lecture 1 Number Systems

High-Precision C++ Arithmetic

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

A Utility for Programming Single FLASH Array HCS12 MCUs, with Minimum RAM Overhead

Using the RDTSC Instruction for Performance Monitoring

Adaptive Stable Additive Methods for Linear Algebraic Calculations

20 Using Scripts. (Programming without Parts) 20-1

Floating-point control in the Intel compiler and libraries or Why doesn t my application always give the expected answer?

Fast Logarithms on a Floating-Point Device

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

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

Adapting the PowerPC 403 ROM Monitor Software for a 512Kb Flash Device

Technical Data Sheet UM-005. UM005-doc In reference to UM005-c-01.04

Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings:

Computer Gateway Specification and Technical Data

Advanced Tutorials. Numeric Data In SAS : Guidelines for Storage and Display Paul Gorrell, Social & Scientific Systems, Inc., Silver Spring, MD

Serial Communications Protocol. Data 2179 Revision 4. For Use With Cooper Power Systems Apparatus Controls: Form 6 Recloser Control

Computer Gateway Specification and Technical Data

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

MUSCLE Cryptographic Card Edge Definition for Java 1 Enabled Smartcards

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

INTERNATIONAL TELECOMMUNICATION UNION

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

MACHINE ARCHITECTURE & LANGUAGE

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

A Adobe RGB Color Space

Computer Architecture Basics

Illustration 1: Diagram of program function and data flow

Appendix C: Keyboard Scan Codes

Transcription:

Mosaic Industries Conversion of HEX ASCII Floating Point Number to Binary IEEE Format APPLICATION NOTE MI-AN-050 Summary The following explains how to convert a HEX ASCII floating point number to binary IEEE format. Description The situation: We have 8 hex ascii bytes coming from the QED Board, and we need to convert these to standard IEEE binary format. Each hex ascii byte represents 4 bits of the QEDformatted FP number. The hex ascii character corresponding to the most significant bits are transmitted first. QED Format: least significant 16 bits (0-15): 16-bit mantissa bits 16-23: signed 2s-complement 8bit exponent (unbiased) bits 24-31: sign: 0xFF -> negative; 0x01 -> positive; 00-> zero IEEE Format: least significant 23 bits (0-22): 23-bit mantissa bits 23-30: biased 8bit exponent; actual exponent = {bits 23~30) - 127. bit 31: sign: 1 -> negative; 0 -> positive Both formats use the "hidden bit" approach, where the magnitude of the result equals {1.mantissa} * {2^exp}; the sign of the result is given by the sign byte or bit. The first 2 hex ascii chars represent the sign byte; this is the most significant byte of the QED FP#. The only valid values are 00, 01, or FF. Any other values represents an error condition ("NAN"). The next 2 hex ascii chars represent the signed 2scomplement exponent of the QED FP#. The final 4 hex ascii chars represent the 16-bit mantissa of the QED FP#. We use C pseudo-code to describe the required transformation. DATA STRUCTURES FOR THE CONVERSION: Declare the following temporary variables: char Qsign_var; char Qexponent_var; char IEEE_sign_var; char IEEE_exponent_var; int IEEE_mantissa_var; Initialize the temporary variables to zero before each conversion. Define the following union and zero it before each conversion {ie, make_fp.shiftable_fp = 0;} union { struct { char sign_exp; // sign bit and 7 bits of exponent int mantissa; // lsbit of exponent and 15 msbits of mantissa char lower_mantissa; // lowest 8 bits of mantissa } fp_parts; unsigned long shiftable_fp; // used to zero union, and to do 1-bit shift float ieee_fp; // final ieee answer is here } make_fp; (Here I'm assuming that your machine stores most-significant byte in low memory; this is true for motorola processors, but you'll have to check for your own application). Mosaic Industries Page 1 of 5 Any questions? Call (510) 790-8222

CONVERSION ALGORITHM: Accept the first 2 hex ascii chars and store the binary value into Qsign_var. If Qsign_var == 00: accept the remaining six hex ascii chars; if all equal 0: exit the conversion routine {result = 32bit zero}. If the remaining 6 chars not= zero: declare an error (invalid FP#) and exit the conversion routine. Acquire the next 2 hex ascii chars; these represent the 8bit QED exponent. Store the binary value into Qexponent_var. Acquire the next 4 hex ascii chars; these represent the 16bit QED mantissa. Store the binary value into make_fp.fp_parts.mantissa If Qexponent_var = 0x7F: Set make_fp.fp_parts.mantissa = 0xFFFF. Else if QED exponent is in the range= 0x80 to 0x83: Set make_fp.fp_parts.sign_exp = 0x82. {Will be 0x01 after we add bias). Set make_fp.fp_parts.mantissa = 0x0000. {Note: QED exponents in range 80 to 83 map onto +/- 1/ieee.infinity} Endif make_fp.fp_parts.sign_exp += 0x7F; // add bias to exponent make_fp.shiftable_fp >> 1; // shift right 1 bit position If Qsign_var = 0xFF, shifted_ieee_fp.sign_exp = 0x80. // set sign bit. If Qsign_var = 0x01, shifted_ieee_fp.sign_exp &= 0x7F. // clear sign bit. Now the floating point number can be referenced as make_fp.ieee_fp DONE \ *********** SOME CONVERSION CORRESPONDENCES *********** MS LS MS LS FP number QED hex IEEE hex 0.0 1.0 00 00 00 00 01 00 00 00 00 00 00 00 3F 80 00 00 2.0 01 01 00 00 40 00 00 00-2.0 1.0E6 FF 01 00 00 01 13 E8 48 C0 00 00 00 49 74 24 00-3.8E-10 FF E0 A1 D1 AF D0 E8 80 \ *********** HC11 ASSEMBLY CODED VERSION: *********** \ the following 2 routines perform conversions in the QED-Forth kernel. \ they are included for reference. Mosaic Industries Page 2 of 5 Any questions? Call (510) 790-8222

7F CONSTANT EXP.BIAS \ offset of exponent for ieee fp format \ must be callable from C CODE FP_QtoC ( qed.fp -- ieee.fp ) \ generates normalized ieee representations: \ sign bit in msbit (bit 31), biased exponent in next 8 bits (23-30); \ mantissa in next 23bits (0-22). zero is always positive. \ maps QED fp with exponent = 7F onto +/-ieee.largest normalized number \ (biased exp. = FF, mant=0) \ maps QED fp with exponent in range 80-83 onto \ ieee exponent = 1, ieee mantissa = 0. 0 IND,Y LDD \ A <- sign byte; B <- exponent EQ IF, RTS \ if sign and exp = 0, result = 0 \ we're counting on valid QED fp number(32bit 0)! 2 IND,Y LDX \ X <- mantissa 7F IMM CMPB \ exponent = 7F maps onto +/- ieee largest num EQ IF, \ ieee exponent will be FE FFFF IMM LDX \ make top 16bits of mantissa=largest possible 83 IMM CMPB \ exponent 80-83 maps onto +/- 1/ieee.infinity LE IF, 82 IMM LDAB \ make exponent 82; ieee result will be 01 0 IMM LDX \ make mantissa 0 for consistent results \ save sign 1 IND,Y STX \ put mantissa into middle 2 bytes 3 IND,Y CLR \ put 0 in lsbyte EXP.BIAS IMM ADDB 0 IND,Y STAB \ exponent + bias into msbyte of scratch CALL -1 CALL DSCALE \ shift right 1 place; msbit gets garbage PULA \ retrieve sign MI IF, \ if sign byte was FF... 80 0 IND,Y BSET \ make it negative 80 0 IND,Y BCLR \ else make it positive RTS END.CODE Mosaic Industries Page 3 of 5 Any questions? Call (510) 790-8222

\ must be callable from C CODE FP_CtoQ ( ieee.fp -- qed.fp ) \ converts denormalized numbers to zero; ie if biased.exp = 0, answer = 0 \ we assume input is valid ieee number; NAN (not a number) inputs are \ converted to +/- infinity depending on sign bit. \ lsbit of mantissa is not rounded, resulting in up to 1 lsbit error \ during the conversion. This is less of a problem because we \ are using this conversion only to print strings, not as intermediate \ steps in math operations. All math is done in the high precision ansi format. 0 IND,Y LDD \ msbit of A = sign; rest of A and msbit of B= exponent ASLD \ A has biased exponent EQ IF, \ if biased exponent = 0, result = 0 CLRB \ we're converting denormalized numbers to 0 also 0 IND,Y STD 2 IND,Y STD PULA \ clear sign byte off rstack RTS ( 0\0 -- ) \ done FF IMM CMPA \ if biased exponent was FF... EQ IF, \ ieee input was a signed infinity CALL FDROP ( -- ) CALL INFINITY PULA \ A <- sign byte MI IF, \ if sign was negative... CALL FNEGATE RTS ( +/-infinity -- ) \ done \ if we're here, input is a nonzero normalized number 2 IND,Y LDX \ X <- lowest 16bits of mantissa;b has other 7 bits MI IF, \ if msbit of X is set... 01 IMM ORAB \ set lsbit of B; B now has top 8 bits of mantissa EXP.BIAS IMM SUBA \ unbias the exponent 1 IND,Y STAA \ put unbiased exponent to dstack PULA \ A <- original sign byte MI IF, FF IMM LDAA 01 IMM LDAA 0 IND,Y STAA \ put sign byte XGDX ASLD \ A has lower 8 bits of QED mantissa XGDX \ B has top 8 bits of QED mantissa 2 IND,Y STAB PULA 3 IND,Y STAA \ put mantissa to stack RTS ( fp -- ) \ done END.CODE Mosaic Industries Page 4 of 5 Any questions? Call (510) 790-8222

// Copyright 1997 Mosaic Industries, Inc. All Rights Reserved. // Disclaimer: THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT ANY // WARRANTIES OR REPRESENTATIONS EXPRESS OR IMPLIED, INCLUDING, BUT NOT // LIMITED TO, ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS // FOR A PARTICULAR PURPOSE. The information provided herein is believed to be reliable; however, Mosaic Industries assumes no responsibility for inaccuracies or omissions. Mosaic Industries assumes no responsibility for the use of this information and all use of such information shall be entirely at the user's own risk. Mosaic Industries 5437 Central Ave Suite 1, Newark, CA 94560 Telephone: (510) 790-8222 Fax: (510) 790-0925 Mosaic Industries Page 5 of 5 Any questions? Call (510) 790-8222