home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / msdos / programm / 8853 < prev    next >
Encoding:
Text File  |  1992-08-27  |  1.4 KB  |  52 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!mcsun!sunic!ugle.unit.no!venaas
  3. From: venaas@siri.unit.no (Stig Venaas)
  4. Subject: Re: Efficient byte/word mirroring request
  5. Message-ID: <1992Aug28.072811.27715@ugle.unit.no>
  6. Sender: news@ugle.unit.no (NetNews Administrator)
  7. Organization: University of Trondheim
  8. References: <1992Aug28.083405.164422@dstos3.dsto.gov.au>
  9. Date: Fri, 28 Aug 92 07:28:11 GMT
  10. Lines: 40
  11.  
  12. In article <1992Aug28.083405.164422@dstos3.dsto.gov.au> egg@dstos3.dsto.gov.au writes:
  13. >Does anyone know how to quickly and efficiently mirror a byte.
  14. >ie
  15. >    11001010 to 01010011
  16. >
  17. >the only way I know is this
  18. >
  19. >   mov  al,byte_to_shift
  20. >   mov  cx,8
  21. >ShiftLoop:
  22. >   rcr  al
  23. >   rcl  ah
  24. >   loop ShiftLoop
  25. >   mov  shifted_byte,ah
  26. >
  27. >There must be an easier (and smarter) way to speed this up using logical
  28. >op's perhaps ?
  29. >Any Help appreciated.
  30. >
  31. >Themie Gouthas
  32. >egg@dstos3.dsto.gov.au
  33.  
  34.  
  35. The fastest way of doing this is to use look up tables.
  36. You could make a look up table for the nibbles. 0000 to 1111. That's
  37. just 16 bytes. You could squeeze it into 8 bytes, but the code
  38. would be longer and it would take more time. Then to mirror a byte,
  39. you just look up the two nibbles, and swap them. This procedure can
  40. be used for words etc. of course.
  41.  
  42. I don't think this algorithm including the table would take much
  43. more space than yours.
  44.  
  45. If time is more important than size, use a look up table for the
  46. bytes.
  47.  
  48.  
  49.  
  50. -- 
  51. Stig (venaas@siri.unit.no)
  52.