Electronics > Microcontrollers

STM8 assembly - some kind of arithmetic op to set carry if two values equal?

(1/2) > >>

HwAoRrDk:
In STM8 assembly language, is there some kind of arithmetic operation I can do that will have the effect of setting the carry flag if two values are equal, and clear the carry if they are not?

I know there is the CP dst, src instruction, but that only sets carry if src is larger than dst. I'm wondering if there is some kind of arithmetic trickery that can be done with possibly other instructions that modify carry, such as ADD, SUB, DIV, etc.

What I'm trying to do is generate a sequence of instructions, without branching, to set/clear several I/O port pins, but the state each is set to depends on whether an argument passed into the function matches its position. I thought the BCCM instruction might be useful here, if I can only get the carry set appropriately...


--- Code: ---LD A, (3, sp) ; load func arg to A reg
; here, set carry = (A == 0)
BCCM 0x5000, #3
; here, set carry = (A == 1)
BCCM 0x5005, #0
; here, set carry = (A == 2)
BCCM 0x5000, #6
; here, set carry = (A == 3)
BCCM 0x500F, #2
; etc...

--- End code ---

rhodges:
Something like this?

--- Code: ---LD A, (3, sp) ; load func arg to A reg
sub a, #1 ; here, set carry = (A == 0)
BCCM 0x5000, #3
sub a, #1 ; here, set carry = (A == 1)
BCCM 0x5005, #0
sub a, #1 ; here, set carry = (A == 2)
BCCM 0x5000, #6

--- End code ---

HwAoRrDk:
Yes! That does the trick. :D

If I'm understanding correctly, by decrementing the position argument itself at each step, the subtraction will have a negative result (i.e. underflow) and the carry bit set when needed. At the subsequent step, it will go back to no carry, as it's just decrementing from 255. I suppose this means I can't have more than 255 steps - as it would underflow twice -  but I don't need to.

I must be having a bit of brain drain today to not be able to think it would be that simple.

Thanks very much. :-+

ucanel:
Sorry for the interruption but after i saw this topic i think it would be efficent to do it with jump  table and i do not know stm8 assembly so i searched for it for more than a hour but could not got it. So i wonder it now :)

My question how is Program Counter manipulation done in Stm8 assembly?
I was doing it for PIC mcus like this:

--- Code: ---MOV      0x04,W  ; load xxx to accumulator (W)
ADDWF PCL,F  ; PC = PC + Accumulator [add accumulator (W) to the Program counter and store it to the File ( Program Counter) ]

--- End code ---

chickenHeadKnob:
In general when I want to do some Boolean operation on an 8 bit micro and it is not directly supported in the instruction set and I want to avoid branching, I resort to 256 byte lookup tables. Input conditions form the index into the table. Might need 2 tables if'n  you need to do something more complicated than set/clear.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version