I'm trying to do a zero or sign extension but without using MOVZX or MOVSX.
I basically want to mimic the said commands, but not use them. Is there a way to do it?
To add 0 from the left there's SHR but I'm not quite sure that it works the same because it changes the value...
I'm using Assembly 8086
All x86-16 CPUs provide the
CBW(8-bit to 16-bit) andCWD(16-bit to 32-bit) instructions.If you want to do a "generic" sign extension (e.g. from 12-bit to 16-bit instead of from 8-bit to 16-bit), you might use the following algorithm that works on any CPU:
ANDto get the highest bit of the word to be extendedExample: Sign-extending
AXfrom 12-bit to 16-bit:The code above may be simplified by working on the high byte of
AXonly (e.g.AND AH, 0xFinstead ofAND AX, 0xFFF).