Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!oliveb!pyramid!ctnews!UNIX386!mark From: mark@UNIX386.Convergent.COM (Mark Nudelman) Newsgroups: comp.arch Subject: Re: Endian reversing MOVEs Message-ID: <10@UNIX386.Convergent.COM> Date: 9 Feb 89 20:00:23 GMT References: <759@atanasoff.cs.iastate.edu> <37562@oliveb.olivetti.com> Organization: Convergent Technologies, San Jose, CA Lines: 24 In article <37562@oliveb.olivetti.com>, chase@Ozona.orc.olivetti.com (David Chase) writes: > [endian-reversing code optimized for the Acorn RISC machine] Interesting method. This could be rendered in 80386 code as: / input value in %eax movl %eax, %edx / edx = (a b c d) 2 clocks rorl $16, %edx / edx = (c d a b) 3 xorl %eax, %edx / edx = (a^c b^d a^c b^d) 2 shrl $8, %edx / edx = (0 a^c b^d a^c) 3 xorb %dh, %dh / edx = (0 a^c 0 a^c) 2 rorl $8, %eax / eax = (d a b c) 3 xorl %edx, %eax / eax = (d c b a) 2 However, since the 386 has instructions to manipulate bytes within 32 bit registers (and doesn't have the shift-and-op features of the Acorn), a faster and simpler version is: xchgb %al, %ah / eax = (a b d c) 3 clocks rorl $16, %eax / eax = (d c a b) 3 xchgb %al, %ah / eax = (d c b a) 3 Mark Nudelman {sun,decwrl,hplabs}!pyramid!ctnews!UNIX386!mark