I think I'm missing something here because this should be easy but I just can't figure out how to display a negative number. I just want my program to output -1 if there is overflow, but it keeps showing 65535 instead. I just don't really understand how negative numbers in general work in 68k. I tried like this:
MOVE.W #-1,D1
MOVE #3,D0
TRAP #15
and like this:
MOVE.W #1,D1
NEG D1
MOVE #3,D0
TRAP #15
So I'm not sure if the problem is only in getting the negative number to display or with storing it or both. Any help is appreciated!
In general, unless one is using a programming language with a built-in way of outputting signed numbers, the proper way to display signed values is to test whether they are negative, and then if so invert them and output a -
. Then use whatever means would be employed for unsigned numbers. In some cases it may be necessary to process the -
after processing everything else (e.g. if one is exploiting the ability of some LCD controllers to process data in right-to-left order, one might output numbers in lowest-digit-first order, stopping once one has a zero residual, then output a "-" if needed, and finally outputting enough blanks to pad the field) but such things may be accommodated by having the "output number" routine accept a parameter indicating what character, if any, should precede the number; the caller could then pass a "+", "-", or " " as appropriate.