Can't add a question about C behavior

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I tried to add a question about weird behavior I'm seeing from my C code, but the "spam filter" blocked the post.

   

I guess it didn't like the code snippet in the body of the post. How can I ask my question?

   

Edit: Maybe I can edit the post enough to ask my question without including code...?

   

This is for a project that interfaces with an 8-bit CPU by emulating RAM/ROM.

   

It works, under some circumstances. There is an if statement for the ROM emulation area (based on what range is being addressed), and the other branch is for the read/write buffer area. Handling the ROM area first is to make it fast enough to execute machine language from, directly. That works, too, sort-of.

   


The catches are:

   

1. There is a Status Read() that already assures that the range addessed will be either ROM or buffer; the ROM part is if the page number is below 12. The second branch should work with just an else, and SHOULD be faster that way, but it actually causes the ROM part to fail if I don't use an else if in the buffer part.

   


2.  I have a function that has a switch statement to do other processing based on a command passed to the last address of the buffer. Right now there is one command in there. If I add a second case to the switch statement, with some calls in that block, that will cause the "ROM" reads to become unreliable - some bytes are read correctly, and some are not.

   


Why should the main loop care how many sections are in the function when I'm not passing any commands or even addressing the section that might cause the function to be called? Why is an else if, with an already known area in the if, faster than a plain else?

   

Please help. This is really making me crazy!

   


Edit again: added the main loop and function in the attached text file. Hopefully you can see it. This is the current code that works... until I uncomment the other lines in req = 2.

   

 

   

Thanks,
​Paul
 

0 Likes
1 Solution
Anonymous
Not applicable

Solved! ... or, at least, solved enough.

   

I couldn't find a way to force the optimizer to keep its mitts off my if/else block, but some co-workers pointed me towards function-specific attributes that I could apply to DoCommand and the commands it calls. By marking those as noinline, I can uncomment the SD commands, and things still work. Hopefully no more surprises...

View solution in original post

0 Likes
2 Replies
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

This is the code that works (main loop and function). It works until I uncomment the other lines in req = 2.

0 Likes
Anonymous
Not applicable

Solved! ... or, at least, solved enough.

   

I couldn't find a way to force the optimizer to keep its mitts off my if/else block, but some co-workers pointed me towards function-specific attributes that I could apply to DoCommand and the commands it calls. By marking those as noinline, I can uncomment the SD commands, and things still work. Hopefully no more surprises...

0 Likes