I'm working with x86 Assembly and I've come accross the need to use the MUL instruction.
My code fragment used to be this:
mov al, <some_number>
mul bl
add al, [edi]
mov [edi], al
Where the <some_number> is a constant defined outside this Assembly fragment, it can be positive or negative. The bl register is set earlier in the code, it's always positive (as it just overflows/underflows whenever fit). I can also probably optimize the last two statements to add [edi], al but I'm not 100% sure so I won't do that just yet.
So my program is hitting undefined behavior, in this case an infinite loop, after checking what could be wrong for a long time I figured that I had to use IMUL because <some_number> could be negative.
But now it still doesn't work. Then I looked again in the manual and I saw that mul bl actually stores the result in ax. So I have a signed result in ax, while I want an unsigned (with overflow/underflow) result in al.
So my question is: How do I turn the signed result in ax in to an unsigned one in al? Basically the opposite of sign-extending.
Note: I've included my thought process here as well because it's quite likely that I'm doing things not as intended and that therefore I couldn't find an answer so far.