2

I want to move 4 bytes, $B1,B2,B3,B4, one at a time, into data register D1.

The value I want in D1 is $B1B2B3B4.

Which instruction(s) will help me do this?

Evorlor
  • 7,263
  • 17
  • 70
  • 141
Plaidypus
  • 81
  • 9

3 Answers3

1

I found a solution using LSL (Thank you, Chris Stratton), and SWAP:

MOVE.B      #$B1,D0
LSL         #8,D0
MOVE.B      #$B2,D0
SWAP        D0
MOVE.B      #$B3,D0
LSL         #8,D0
MOVE.B      #$B4,D0
Plaidypus
  • 81
  • 9
1

There's no point in using SWAP to do this, just combine moves, ors and shifts:

MOVE.B  #$B1, D0  ; D0 now $xxxxxxB1
LSL.L   #8, D0    ; $xxxxB100
ORI.B   #$B2, D0  ; $xxxxB1B2
LSL.L   #8, D0    ; $xxB1B200
ORI.B   #$B3, D0  ; $xxB1B2B3
LSL.L   #8, D0    ; $B1B2B300
ORI.B   #$B4, D0  ; $B1B2B3B4

Maybe it's not shorter or faster, but at least I think it's clearer.

unwind
  • 391,730
  • 64
  • 469
  • 606
0

Sometimes you can just be direct about it:

MOVE.L #$B1B2B3B4,D0

(shrug)

There are clever ways to do what you want if you need to save memory or run very fast.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
Dave Small
  • 31
  • 1