Long types are signed. Use SDEC instead of # to format for printing.
Long types are signed. Use SDEC instead of # to format for printing.
Charles Leo has replied to my email as follows.
It is the "#" modifier in your commands that is giving you incorrect displayed results. The "#" modifier is only intended for use with variables less than 16-bit. This makes it impossible to display LONG decimal values with SEROUT, but you can use the "DEC" modifier with DEBUG, SEROUT2, and HSEROUT.
Try these display lines:
debug "Debug version ", DEC lw, ",", DEC lx, ",", DEC ly,_
",", DEC lz , $0D, $0A
serout2 tx232, 84, [ "Serout2 version ", DEC lw, ",",_
DEC lx, ",", DEC ly, ",", DEC lz, $0D, $0A ] hserout ["HSEROUT version ", DEC lw, ",", DEC lx, ",",_
DEC ly, ",", DEC lz, $0D, $0A]
I've noted your points for the next manual revision. I'm planning some samples that demonstrate applications for LONGs.
Simply put, use LONGs when you need to store a negative value or a value larger than 65535.
Charles Leo
Looks to me like SEROUT2 or DEBUG with the SDEC modifier become the preferred serial output modes. They both allow modifiers like DEC and SDEC which plain SEROUT does not. They are also 'self contained' instructions and do not need any interrupt bit clearing like HSERIN/OUT requires.
Division is still an issue and whether the minus sign is just a convenience for human readers or can actually be used within a PBP calculation is still untested.
This code,
LongTest:
'Mult & Div
lw = 1234
lx = 4321
ly = LX * lw
lz = lx/lw
debug $0D, $0A, "Multiply & Divide A, B, (A*B), (A/B)", $0D, $0A
debug "Debug DEC ", dec lw, ",", dec lx, ", ", dec ly, ", ", dec lz , $0D, $0A
serout2 tx232, 84, [ "Serout2 DEC ", dec lw, ",", dec lx, ",", dec ly, ",", dec lz, $0D, $0A ]
debug "Debug SDEC ", sdec lw, ",", sdec lx, ", ", sdec ly, ", ", sdec lz , $0D, $0A
serout2 tx232, 84, [ "Serout2 SDEC ", sdec lw, ",", sdec lx, ",", sdec ly, ",", sdec lz, $0D, $0A ]
' Serout tx232, 2, ["Serout version ", dec lw, ",", dec lx, ",", dec ly, ",", dec lz, $0D, $0A ]
'Add & Subtr
lw = 65534
lx = 66000
ly = lw + lx
lz = lw - lx
debug $0D, $0A, "Add & Subtract A, B, (A+B), (A-B)" , $0D, $0A
debug "Debug DEC ", dec lw, ",", dec lx, ",", dec ly, ",", dec lz , $0D, $0A
serout2 tx232, 84, [ "Serout2 DEC ", dec lw, ",", dec lx, ",", dec ly, ",", dec lz, $0D, $0A ]
debug "Debug SDEC ", sdec lw, ",", sdec lx, ",", sdec ly, ",", sdec lz , $0D, $0A
serout2 tx232, 84, [ "Serout2 SDEC ", sdec lw, ",", sdec lx, ",", sdec ly, ",", sdec lz, $0D, $0A ]
' Serout tx232, 2, ["Serout version ", dec lw, ",", dec lx, ",", dec ly, ",", dec lz, $0D, $0A ]
Gives these results
Multiply & Divide A, B, (A*B), (A/B)
Debug DEC 1234,4321, 5332114, 3
Serout2 DEC 1234,4321,5332114,3
Debug SDEC 1234,4321, 5332114, 3
Serout2 SDEC 1234,4321,5332114,3
Add & Subtract A, B, (A+B), (A-B)
Debug DEC 65534,66000,131534,4294966830
Serout2 DEC 65534,66000,131534,4294966830
Debug SDEC 65534,66000,131534,-466
Serout2 SDEC 65534,66000,131534,-466
Bookmarks