From: korpela AT albert DOT ssl DOT berkeley DOT edu (Eric J. Korpela) Newsgroups: comp.os.msdos.djgpp Subject: Re: Quick inline asm question... Date: 19 Sep 1996 17:54:34 GMT Organization: Cal Berkeley-- Space Sciences Lab Lines: 62 Message-ID: <51s1cq$epe@agate.berkeley.edu> References: <51mrb2$o5f AT news DOT cais DOT com> NNTP-Posting-Host: albert.ssl.berkeley.edu To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp In article <51mrb2$o5f AT news DOT cais DOT com>, David Charlton 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. Click here for more info.