How do I move a byte into a specific location in a data register?

369 views Asked by At

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?

3

There are 3 answers

0
Plaidypus On BEST ANSWER

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
0
unwind On

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.

0
Dave Small On

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.