Hi. Why does TI need to be set before printf is called.
TI = 1; printf("Hello world\n");
Whereas in assembly TI should be cleared before a char is put in SBUF, so it can be tested to see if the char has been sent
This is because the lib routine 'putchar.c' which is called by printf will be in a hard loop waiting for !TI. The following fragment is taken from the putchar.c source code in the Lib folder. You can modify or write your own putchar. You "Hello World" code had to set the TI bit the first time though the call.
while (!TI); TI = 0; return (SBUF = c);
Actually you Only need to set it 1 time at the begining on the program
"Why does TI need to be set before printf is called"
It is nothing specifically to do with printf - it's a "feature" of the default putchar implementation provided by Keil.
If you don't like the way that the default putchar implementation provided by Keil works, you are completely free to provide your own implementation!
The instructions to do that are provided in the documentation for printf.
"in assembly TI should be cleared before a char is put in SBUF, so it can be tested to see if the char has been sent"
Again, that's nothing specifically to do with assembler - that's just the way you've chosen to implement it in your assembler.
There is nothing to stop you making a similar implementation in 'C'...
I didn't say I didn't like it. Of course I can write my own version of printf. But I see now the reason now. I don't notice the file putchar.c. Thanks.