From: alaric AT abwillms DOT demon DOT co DOT uk (Alaric B. Williams) Newsgroups: comp.os.msdos.djgpp Subject: Re: Quick inline asm question... Date: Fri, 20 Sep 1996 18:18:24 GMT Lines: 83 Message-ID: <843243462.28476.1@abwillms.demon.co.uk> References: <199609190031 DOT KAA02429 AT gbrmpa DOT gov DOT au> NNTP-Posting-Host: abwillms.demon.co.uk To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp leathm AT solwarra (Leath Muller) wrote: >You can add a register to itself...its a great way to do a quick multiply. >(x 2). As for adding a 16 bit register to a 32bit one, what you could do is >make sure the top 16 bits of a 32 bit register are zeroed, and perform >an addl. using another register ie: > xorl %%ebx, %%ebx // 1 cycle > movw %%ax, %%bx // 2 cycles > addl %%ebx, %%eax // 1 cycle If your 16 bit number might be negative, padding with zeros won't work; you need to use an instruction called movsx in intel syntax, "move with sign extension". Erm... the AS info entries say: ---------------8<-------------- Almost all opcodes have the same names in AT&T and Intel format. There are a few exceptions. The sign extend and zero extend instructions need two sizes to specify them. They need a size to sign/zero extend *from* and a size to zero extend *to*. This is accomplished by using two opcode suffixes in AT&T syntax. Base names for sign extend and zero extend are `movs...' and `movz...' in AT&T syntax (`movsx' and `movzx' in Intel syntax). The opcode suffixes are tacked on to this base name, the *from* suffix before the *to* suffix. Thus, `movsbl %al, %edx' is AT&T syntax for "move sign extend *from* %al *to* %edx." Possible suffixes, thus, are `bl' (from byte to long), `bw' (from byte to word), and `wl' (from word to long). --------------8<-------------- So I guess to add %bx to %eax we could: movswl %bx,%ebx addl %ebx,%eax Assuming movswl likes both operands being the same register (in a different guise)! If the 16 bit number starts in %ax, consider one of these babies (with different scissors!): -------------B<--------------- The Intel-syntax conversion instructions * `cbw' -- sign-extend byte in `%al' to word in `%ax', * `cwde' -- sign-extend word in `%ax' to long in `%eax', * `cwd' -- sign-extend word in `%ax' to long in `%dx:%ax', * `cdq' -- sign-extend dword in `%eax' to quad in `%edx:%eax', are called `cbtw', `cwtl', `cwtd', and `cltd' in AT&T naming. `as' accepts either naming for these instructions. -------------B<--------------- Ie, to add %ax to %edx: cwtl addl %eax,%edx I presume cwtl is faster that movswl %ax,%eax! >Leathal. ABW (who loves the 386 instruction set!) --- COMPUTER: We are in position over the Rebel homeworld. VADAR: Engage the Death Star primary weapon, let those rebel worms die! COMPUTER: Sorry, your evaluation version of Battle Computer 3.0 has expired. Please send 2.6 billion dollars to the address in REGISTER.TXT Alaric B. Williams Internet : alaric AT abwillms DOT demon DOT co DOT uk Hello :-)