kascefone.blogg.se

Stm8 free c compiler
Stm8 free c compiler












stm8 free c compiler stm8 free c compiler

The programming manual describes what the instruction does: it saves the high and low bytes of Program Counter (PC) register on the stack and loads PC with the destination address of the function being called. Just like with pointers in C you can think of ldw (x), y as *((uint16_t *) &x) = y.īut what’s the deal with those values - 0x03 and 0x05? When we call a function, we (unsurprisingly) issue a call instruction. This value is then treated as a memory address, and the processor loads the value from that address into register X. Here’s how you read it: we get a value from the stack located at. Now for the function itself - the first instruction is ldw x, (0x03, sp). globl - that means we make a symbol accessible from the outside world, and. But I would still prefer doing it the ‘right way’, since this would allow inlining the function without any consequences:Īll right, let’s figure out what’s going on here. The second one means that any register modified by the function must be restored by the function itself when the it returns.Īccording to the documentation, SDCC uses caller saves convention by default, which means that we can implement our functions without saving the context. The first one means that functions are allowed to modify registers as they please and function caller is responsible for saving and restoring context. There are two calling conventions for assembly functions: caller saves and callee saves. That being said, in our case saving registers is not really necessary.

stm8 free c compiler

The proper way is to save the contents of the registers before altering them and restore them afterwards. The compiler does not know about this - it just places assembly instructions where we told it to. There’s a slight issue with this function, though: we’re modifying a commonly used register X, which means that if some value was loaded before calling the function, it will be lost.














Stm8 free c compiler