This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Is there a more efficient way to swap two bytes?

I am targeting a Cortex-M0 processor, and am new to Thumb assembly available on the M0. Is there more efficient way to swap two bytes in a 32-bit word (in this example, the middle two bytes)? Thanks!

  LDR R0, =0xAABBCCDD
  LDR R1, =0x00FF0000
  LDR R2, =0x0000FF00
  MOV R3, R0
  MOV R4, R0
  ANDS R3, R1
  ANDS R4, R2
  BICS R0, R1
  BICS R0, R2
  LSRS R3, #8
  LSLS R4, #8
  ORRS R0, R3
  ORRS R0, R4

Parents
  • LOL The only homework this 50 year old has is sweeping. I cut my teeth on a 6502 (OSI Challenger 2P, VIC-20, etc.) but have recently gotten back into assembly language for fun. There doesn't seem to be a Rodnay Zaks out there for the Cortex-M. Any recommendations for a practical (non-text-book) Cortex-M assembly language/patterns book?

    And thanks for the homework :-). I'll see if I can't get it down to 8 instructions. I appreciate the challenge.

Reply
  • LOL The only homework this 50 year old has is sweeping. I cut my teeth on a 6502 (OSI Challenger 2P, VIC-20, etc.) but have recently gotten back into assembly language for fun. There doesn't seem to be a Rodnay Zaks out there for the Cortex-M. Any recommendations for a practical (non-text-book) Cortex-M assembly language/patterns book?

    And thanks for the homework :-). I'll see if I can't get it down to 8 instructions. I appreciate the challenge.

Children