A89: TIOS functions disobey register conventions!
[Prev][Next][Index][Thread]
A89: TIOS functions disobey register conventions!
I have just discovered that some TIOS functions don't obey they standard
register conventions (allowing changes only to D0/D1/D2/A0/A1). In
particular, OSContrastUp trashes the upper word of the D4 register. I
only actually verified this under AMS version 1.05 and 2.04, though I have
a bad feeling the same thing will happen on other versions as well.
I uncovered this while working on a program in TIGCC which contained a
contrast changer. It crashed for no apparent reason, but after examining
further, I discovered the TIOS was the problem (since only the upper words
are trashed, if the registers were only keeping integers, the problem
might be unnoticd).
I'm not exaclty sure how many TIOS functions do stuff like this, but it is
certainly an annoying problem for only one function.
As a brief example, try compiling and running this (I used TIGCC 0.9, but
it probably doesn't matter much):
--------
#define SAVE_SCREEN
#include <nostub.h>
#include <all.h>
int _ti89;
register long x asm("d4");
void _main(void) {
clrscr();
x = 123456789;
printf("%ld\n", x);
OSContrastUp();
printf("%ld\n", x);
while (!(kbhit()));
}
--------
What should you see when you run this program? It seems clear that it
will simply display the number 123456789 twice on screen, with the
contrast increased one step, and then wait for you to press a key.
Since D4 is a register which should be preserved by function calls, it
seems perfectly safe to assign a variable to it. Looking at the assembly
code generated by TIGCC shows there should be no problems.
However, if you actually run it, you will see that it displays -13035 the
second time! This seems to make no sense, until of course you consider
that the OS contrast adjust function trashes the upper half of the D4
register, a very annoying side effect, to say the least (as it can
sometimes cause crashes!)
Follow-Ups: