This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

A bug in C166 v.4.27

The C166 compiler generates incorrect code when using __inline functions with bit return type. Test source code:

bit bitvar1 = 1;
bit bitvar2;

__inline bit test()
{
	return bitvar1;
}

void main()
{
	bitvar2 = test();
}
In the disassembly window of the simulator the generated code looks like this:
     9: void main()
    10: {
0000000A 4A00F000  BMOV     R0.0,0xFD00.0
    11:         bitvar2 = test();
0000000E 4AF00001  BMOV     0xFD00.1,R0.0
    12: }
00000012 CB00      RET
which is obviously wrong since the user stack pointer R0 gets corrupted. If we add local variables to test the use of the user stack pointer we will see that a word memory access on odd address will be generated because of the corrupt R0.
When compiling via SRC file and assembler everything is different:
; line 4: __inline bit test()
; line 5: {
; line 6: 	return bitvar1;
	BMOV	R4.0,bitvar1
; line 7: }
	RET
; line 8:
; line 9: void main()
; line 10: {
; line 11: 	bitvar2 = test();
	CALL	test
	BMOV	bitvar2,R4.0
; line 12: }
	RET
We can see that the __inline keyword is ignored here and the code is correct.

- mike

Parents
  • Hi Mike, hi Holger

    I was reading this interesting fact and
    if I have time I will try out this here.
    Using the V427 too.

    Why I answer is the RvB?1?test,bitvar
    Mike concerns of.

    I play for some demonstration purposes with
    µVision2 Linker/Locator.
    This seems to be a codesegment you can see in map-file.
    ( Hope that I avoid to making angry Mike,
    he seems very competent on the C166 area )

    I think it means
    Return virtually Bit or
    more likely
    Return value Bit with a size of one bit from code section or module "test" and parameter is "bitvar" what would be identically with that, what Mike wrote.

    Hope this can help you to better understand the code, since some new features are not well documented.

    "Sorry" again for interrupting this dialog,
    I will observe your results and try a test on friday.

    Stefan

Reply
  • Hi Mike, hi Holger

    I was reading this interesting fact and
    if I have time I will try out this here.
    Using the V427 too.

    Why I answer is the RvB?1?test,bitvar
    Mike concerns of.

    I play for some demonstration purposes with
    µVision2 Linker/Locator.
    This seems to be a codesegment you can see in map-file.
    ( Hope that I avoid to making angry Mike,
    he seems very competent on the C166 area )

    I think it means
    Return virtually Bit or
    more likely
    Return value Bit with a size of one bit from code section or module "test" and parameter is "bitvar" what would be identically with that, what Mike wrote.

    Hope this can help you to better understand the code, since some new features are not well documented.

    "Sorry" again for interrupting this dialog,
    I will observe your results and try a test on friday.

    Stefan

Children
No data