Mail Archives: djgpp/1996/09/19/16:06:27
In article <51mrb2$o5f AT news DOT cais DOT com>,
David Charlton <charlton AT the-hermes DOT net> wrote:
> Okay, I have a quick question, if it's really easy or stupid
>please don't flame me... anyway, suppose I wanted to add one of the
>16-bit registers to a 32-bit register (this is for a basic graphics
>routine) -- how would I do that? I've tried "addw %%ax, %%eax", and "addl
>%%ax, %%eax", but it doesn't work. I have a feeling it should be simple,
>but if it's simple it isn't obvious (to me) ;)... so what do I do?
> Thanks in advance...
You have a couple of choices depending upon whether your 16 bit quantity
is signed or unsigned. Here we are adding the 16 bit quantity in ax to
the 32 bit quantity in ebx.
for unsigned addition....
xor %ecx,%ecx
movw %ax,%cx
addl %ecx,%ebx
--or--
movzwl %ax,%ecx
addl %ecx,%ebx
--or--
shll $16,%eax
shrl $16,%eax
addl %eax,%ebx
--or--
andl $0x0000FFFF,%eax
addl %eax,%ebx
+many more
For signed addition...
cwtl
addl %eax,%ebx
--or--
movswl %ax,%ecx
addl %ecx,%ebx
--or--
shll $16,%eax
sarl $16,%eax
addl %eax,%ebx
+ many more
Eric
--
Eric Korpela | An object at rest can never be
korpela AT ssl DOT berkeley DOT edu | stopped.
<a href="http://www.cs.indiana.edu/finger/mofo.ssl.berkeley.edu/korpela/w">
Click here for more info.</a>
- Raw text -