Temp Varable with SXB
Good Morning,
Jonny Mac recently posted a neat series of routines that printed out bin hex and Dec results from Byte parameters.· I thought that was really cool but needed a Decimal printout of a Word Varable.· So I edited his routine and came up with the following:
'
' Use: TX_DEC5 value
' -- transmit word in (fixed-width) DEC5 format
'
SUB TX_DEC5
·dvalW· VAR TmpW1
·divisorW VAR tmpW2
·dDigit· Var tmpB1
·dChar· Var tmpB2
· dValW = __wPARAM12······················ ·' copy output value
· divisorW = 10000···························· ··' set initial divisor
· FOR dDigit = 4 TO 0 STEP -1············ · ·' show three digits
··· __wparam34 = dValW / divisorW·········· ' get a digit
··· dValW = __wREMAINDER··············· ··· ·' save remainder
·· dChar = __param3··························· ·' it going to be <10
·· dChar = dChar + "0"·························· ' convert to ASCII
··· TX_BYTE dChar
··· divisorW = divisorW / 10··············· ···· ' update divisor
· NEXT
·
ENDSUB
if I declare tmpW1 = 23456· or any 5 digit number short of 65,535:
·· TX_DEC5 tmpW1
my results always come out 00000.
I wonder if I have one temp varable stepping on another.· When I look at .lst file I do find some VAR with the same address.· I am I missing something?· It is hard to step through the Devide by 10,000 to see what is happening.· I tried setting dChar = dValw / divisorW but it is expecting a word param not a byte and wont compile.
Jonny Mac recently posted a neat series of routines that printed out bin hex and Dec results from Byte parameters.· I thought that was really cool but needed a Decimal printout of a Word Varable.· So I edited his routine and came up with the following:
'
' Use: TX_DEC5 value
' -- transmit word in (fixed-width) DEC5 format
'
SUB TX_DEC5
·dvalW· VAR TmpW1
·divisorW VAR tmpW2
·dDigit· Var tmpB1
·dChar· Var tmpB2
· dValW = __wPARAM12······················ ·' copy output value
· divisorW = 10000···························· ··' set initial divisor
· FOR dDigit = 4 TO 0 STEP -1············ · ·' show three digits
··· __wparam34 = dValW / divisorW·········· ' get a digit
··· dValW = __wREMAINDER··············· ··· ·' save remainder
·· dChar = __param3··························· ·' it going to be <10
·· dChar = dChar + "0"·························· ' convert to ASCII
··· TX_BYTE dChar
··· divisorW = divisorW / 10··············· ···· ' update divisor
· NEXT
·
ENDSUB
if I declare tmpW1 = 23456· or any 5 digit number short of 65,535:
·· TX_DEC5 tmpW1
my results always come out 00000.
I wonder if I have one temp varable stepping on another.· When I look at .lst file I do find some VAR with the same address.· I am I missing something?· It is hard to step through the Devide by 10,000 to see what is happening.· I tried setting dChar = dValw / divisorW but it is expecting a word param not a byte and wont compile.
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
You can't use __WPARAM34 as the result of a division because those bytes (__PARAM3 and __PARAM4) are actually used to hold the divisor during the division -- your code is clobbering the divisor as it runs. I've been "looking under the hood" a lot and finding areas where internal variables can be used; here are some examples.
As you can see there are very limited opportunities to use internal variables with TX_DEC5 -- sometimes it just works that way.
Post Edited (JonnyMac) : 8/23/2008 9:49:23 PM GMT
Post Edited (JonnyMac) : 8/23/2008 9:46:21 PM GMT
[noparse][[/noparse]Edit] After having a bit of lunch I was able to trim all thre TX_DEC type routines. Note that the order of instructions is important due to the use of internal variables where possible.
Post Edited (JonnyMac) : 8/23/2008 9:48:35 PM GMT
I suspected that I was stepping on one of the temp variables.· Is there anywhere that their addresses are listed so that we can determine ahead of time when not to use a particular temp variable?· Or do I have to print out the variable section of the .lst file and go through it with a fine tooth comb?· I really appreciate the code as it should help what I am doing a lot.
JIm