Skip to main content
Graduate
October 1, 2024
Solved

BSET BRES with dynamic position

  • October 1, 2024
  • 2 replies
  • 1355 views

Hello, I'm successfully using BSET and BRES assembler instructions where the position is constant. However, I'm having trouble getting it to work where the position is determined at runtime.

For example:

 

bset 0x500f, 2 ; works
ldw x, (0x03, sp)
bset 0x500f, x ; doesn't work

 

I've looked at several sites, but all seem to have constant positions.

One workaround would be to have a full list of BSET instructions, one for each position, and jump to the appropriate instruction based on a decision. This wouldn't be bad necessarily, but hoping for a better way.

 

References:

assembler instructions datasheet in PM0044, section 7 (specifically 7.4): https://www.st.com/content/ccc/resource/technical/document/programming_manual/43/24/13/9a/89/df/45/ed/CD00161709.pdf/files/CD00161709.pdf/jcr:content/translations/en.CD00161709.pdf

lujji's very helpful blog post: https://lujji.github.io/blog/mixing-c-and-assembly-on-stm8/

eforth: https://github.com/TG9541/stm8ef/wiki/STM8-eForth-Compiler-and-Assembly

a nice GitHub repo: https://github.com/search?q=repo%3Aaaw20904%2FSTM8_library%20bset&type=code

    This topic has been closed for replies.
    Best answer by Peter BENSCH

    In fact, BSET, like all other bit operation instructions, can only be called with constants. There are two reasons for this: firstly, the instruction is executed in one cycle, which does not allow a variable to be fetched, and secondly, it only consists of 4 bytes, so there is no room for pointers.

    Alternatively, you can also set bits in variables via the OR statement, but this increases the effort considerably because the variable must first be buffered in the accumulator and then moved back.

    Regards
    /Peter

    2 replies

    Technical Moderator
    October 17, 2024

    In fact, BSET, like all other bit operation instructions, can only be called with constants. There are two reasons for this: firstly, the instruction is executed in one cycle, which does not allow a variable to be fetched, and secondly, it only consists of 4 bytes, so there is no room for pointers.

    Alternatively, you can also set bits in variables via the OR statement, but this increases the effort considerably because the variable must first be buffered in the accumulator and then moved back.

    Regards
    /Peter

    Graduate
    October 17, 2024

    Thank you for the clarification. As a side note, since writing the question I've become more familiar with the PM0044 doc, where the details make it more clear that only constants are available.