Format floating point number into double-byte fixed point number

Publisher:科技奇思Latest update time:2015-02-03 Source: laogu Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Label: FTOD Function: Convert the formatted floating point number into a double-byte fixed point number

Entry condition: Formatted floating-point operand in [R0].
Exit information: OV=1 overflow, OV=0 conversion success: The absolute value of the fixed-point number is in [R0] (double byte), the sign
is in bit 1FH, F0=1 is an integer, CY=1 is a one-byte integer and a one-byte decimal, otherwise it is a pure decimal.
Affected resources: PSW, A, B, R2, R3, R4, bit 1FH Stack requirements: 6 bytes
FTOD: LCALL MVR0; transfer [R0] to the first work area
MOV A, R2
JZ FTD4; the exponent is zero, pure decimal
JB ACC.7, FTD4; the exponent is negative, pure decimal
SETB C
SUBB A, #10H
JC FTD1
SETB OV; the exponent is greater than 16, overflow
RET
FTD1: SETB C
MOV A, R2
SUBB A, #8; is the exponent greater than 8?
JC FTD3
FTD2: MOV B,#10H ; if the exponent is greater than 8, convert it as a double-byte integer
LCALL FTD8
SETB F0 ; set up a double-byte integer flag
CLR C
CLR OV
RET
FTD3: MOV B,#8 ; convert it as a one-byte integer to a one-byte decimal
LCALL FTD8
SETB C ; set up a one-byte integer to a one-byte decimal flag
CLR F0
CLR OV
RET
FTD4: MOV B,#0 ; convert it as a pure decimal
LCALL FTD8
CLR OV ; set up a pure decimal flag
CLR F0
CLR C
RET
FTD8: MOV A,R2 ; right-normalize according to the specified number of integer digits
CJNE A,B,FTD9
MOV A,R3 ; transfer the double-byte result to [R0]
MOV @R0,A
INC R0
MOV A,R4
MOV @R0,A
DEC R0
RET
FTD9: CLR C
LCALL RR1 ; right-normalize once
SJMP FTD8

Reference address:Format floating point number into double-byte fixed point number

Previous article:Convert floating point BCD code into formatted floating point number
Next article:Convert a double-byte hexadecimal fixed-point number into a formatted floating-point number

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号