Date: Thu, 19 Sep 1996 01:25:17 -0700 (PDT) From: Samuel Vincent To: leathm AT gbrmpa DOT gov DOT au cc: Mihai Moise , djgpp AT delorie DOT com Subject: Re: Quick inline asm question... In-Reply-To: <199609190031.KAA02429@gbrmpa.gov.au> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Thu, 19 Sep 1996, Leath Muller wrote: > > > Well, in as much as I understand 16 vs 32-bit assembly, the 'e*x' > > > registers > > > are simply 32-bit extended versions of the '*x' registers. So, %%ax is > > > in > > > actuality the lower 16 bits of %%eax. What you are trying to do is add > > > the register to itself, which I doubt will work. > > > Actually, adding a register to itself just might work. But intel > > provides no opcodes to mix 16-bit and 32-bit registers in an > > instruction. Besides, even if such opcodes existed, the resulting > > algorithm would not be portable. > > 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 > > Leathal. Well if all you wanted was to multiply by two... I believe shifting the register over by one bit would accomplish this in a lesser amount of time. As far as adding one 16 bit register to a 32 bit register... You have the best way there.. Zero a spare 32 bit register (spare register on an x86 cpu you say? yeah right ;) Move the 16 bit register to the 16 bit register occupying the lower 16 bits of the 32-bit register you just cleared. (In other words clear ebx, then move something into bx) Then ebx becomes a a 32-bit register holding the same value your original 16 bit register did.. Allowing you to use it with all the other nifty 32-bit registers. Now I know of zero-extend op-codes.. but I'm unsure as to what these really are.. (I don't remember).. They may be addition, multiply, whatever.. -Sam