68000- How to move a hexadecimal number in a register 2 units to the left?

1k views Asked by At

I want to move the number 01,02,03,04 individually into the register D1 so that after all the moves have completed the result in register D1 will be 01020304.

The way I'm thinking of solving this problem is, move 01 to D1. Then somehow shift it 2 digits to the left and then move 02 in. And so on to get the solution.

How should I do this?

1

There are 1 answers

0
Durandal On

this can be done in several ways, the most logical is to load the intended topmost byte first, then left-shift the register (by 8 bits = 1 byte) and load the next byte:

 move.b #$01,d0
 lsl.w #8,d0      ; could lsl.l here, too
 move.b #$02,d0
 lsl.l #8,d0
 move.b #$03,d0
 lsl.l #8,d0
 move.b #$04,d0
 ; d0 = $01020304

A somewhat more confusing, but (on the 68000) faster method is load the most significant word as desribed above into the lower word, then use the SWAP instruction to switch register halves, then load the least significant word normally:

 move.b #$01,d0
 lsl.w #8,d0
 move.b #$02,d0
 swap d0
 move.b #$03,d0
 lsl.w #8,d0
 move.b #$04,d0
 ; d0 = $01020304

The point here is that SWAP performs a rotate by 16 on the entire register, so the individual rotations can be performed using word sized shifts. Also, since the 68000 doesn't have a barrel shifter, shifting performance is dependent on shift distance, meaning shifting a register by 8 is relatively slow, while SWAP performs quickly.

On the "bigger" 68K members you won't see much performance difference, because they shift quickly, regardless of shift distance.