Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Lbl DISPFIX
- ;Display a fixed-point number
- ;Important chars:
- ; 48~57 are "0" to "9"
- ; 26 is the negative sign
- ; 46 is the decimal point
- ;First, check if it is negative.
- ;If so, display a negative sign.
- ;On the calcs, that is char(26)
- r1->A
- If A<=32768
- Disp 26>Char
- -A->A
- End
- ;Skip leading zeros.
- ;We'll set Z=0 until we get our first non-zero digit
- ;Now A is on [0,128]
- ;To get the first digit, just check if A>=100
- A>=100.00->Z
- If Z
- A-100.00->A
- Disp 49>Char
- End
- ;Now A is on [0,99]
- ;Subtract 10 until A is <10, incrementing our digit.
- ;Set B to 48, since that is "0"
- 48->B
- While A>=10.0
- 1->Z
- B+1->B
- A-10.0->A
- End
- If Z
- Disp B>Char
- End
- ;Now display the last digit, even if it is 0 and the previous ones were 0
- Disp A/256+48>Char
- ;Now discard the integer part
- ;Do this by getting the bottom 8 bits
- ;We'll use the MOD function, ^ in Axe
- A^256->A
- ;A is on [0,1)
- ;If A is 0, exit
- ReturnIf A=0
- ;Display a decimal
- Disp 46>Char
- ;Now multiply A by 10 and display anything after the decimal
- ;Then discard the integer part
- A*10->A
- Disp A/256+48>Char
- A^256->A
- ;If A<.01, the rest of the digits will be 0, so don't bother
- ;For this, we'll actually use the integer representation
- ;and check if A<3 (.01*256 = 2.56 is less than 3)
- ReturnIf A<3
- ;Multiply A by 10 again to get the next digit
- ;Then discard the integer part
- A*10->A
- Disp A/256+48>Char
- A^256->A
- ;Now exit if A<.1
- ;We'll use A<26 since .1*256 = 25.6 is less than 26)
- ReturnIf A<26
- ;Now display the last digit
- Disp A*10/256+48>Char
- Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement