Hi There!Not sure if this has been addressed but instantiating an lpm_add_sub function with carry in- and out under 9.0sp2 (IIRC) for Flex 10K seems to have some peculiar behavior. The add / adc works as advertised whereas the sub/sbc seems to have... problems. For instance, using unsigned 8-bit, subtracting one from 128 (0x80) results in 0x7e *with* a carry, which obviously is wrong.. The reason I've been going for LPM functions for some of these is that they're more resource friendly as the synthesis isn't all that great in recognizing counters, adders, etc. I'll poke around tonight and isolate it but without carry in/out, I've never had issues IIRC. -Mux Edit: Isolating the addsub function and running the same values as the waveforms seems to give the correct result, so I guess I need to double check what's wrong.. Will let you folks know for completeness!
Alright, figured it out.. While I blindly duplicated the waveform figures it appears that the carry needs to be inverted for subtraction. This makes total sense when you think about it being two's complement and using the adder, but it's not documented anywhere, as far as I can see..So yeah, RTFM and watch those waveforms! -Mux