Question on MOVE Instruction Behavior

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Question on MOVE Instruction Behavior

Jump to solution
1,271 Views
dan_filbey
Contributor II

My question is: How do the MOVE.B or MOVE.W instructions behave when the source is a byte or word, but the destination is a long register (e.g. D0)?

For example, Figure 1 describes memory contents before a MOVE.B:

pastedImage_4.png

Assuming the instruction is something like: MOVE.B (A0), D0  ; Move indirect byte at A0 into D0

Does the execution of the instruction perform the behavior described in Figure 2 or Figure 3:

pastedImage_2.png

pastedImage_1.png

For either answer, where does a datasheet describe the behavior? The descriptions of MOVEQ, MOV3Q, and MOVEA in the CFPRM (https://www.nxp.com/docs/en/reference-manual/CFPRM.pdf) match Figure 3, but the description for MOVE (PDF pg. 123 or printed pg. 4-47) is not clear on its behavior.

Edit: Followup question if Figure 3 is correct: Would the 0xAA value be sign-extended to 0xFFFFFFAA?

0 Kudos
1 Solution
1,143 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

There is a training material about ColdFire core, which provide some info for your reference.

The memory organization with below types: byte, word and long word.

pastedImage_1.png

From the ColdFire programmer reference maual, MOVE intruction support opreation size: B, W, L,

pastedImage_2.png

Then I think MOVE intruction use Figure 2 to transfer byte data to register.

Thanks for the attention.

best regards,

Mike

View solution in original post

4 Replies
1,143 Views
dan_filbey
Contributor II

Thank you both for your answers.

0 Kudos
1,143 Views
TomE
Specialist II

In case the design appears a little strange, it is. The original 68000 instruction set was more symmetric. The 68000 CPU could perform the same operations on bytes, words or longs. Almost all of the arithmetic operations had byte, word and long forms, and operated on both registers and memory. So it was possible to write code where all variables (in memory or in registers) are treated as being of a particular length, and just use the right forms. You could even perform a signed addition of a byte from memory to memory in one instruction (with four extension words if the addressing modes required) and get the correct condition codes for that operation.

The Coldfire simplified the instruction set. All arithmetic operations are now 32-bit, except for CLR, CMP and the bit ops. The shifts went from B/W/L to Long only. The useful Rotates (you could do a lot with B/W/L rotates with and without the X bit) were removed. A lot of the arithmetic operations now only have register forms.

You can't add a byte from memory. You have to load it, then add. You could add 32-bit words from memory that included the byte-of-interest as the low byte to a register, and then store that byte back, but the condition codes would be wrong. It is unlikely a compiler would do anything like that either. What the compiler does do when you need to test condition codes (just checked) is "moveb %a2@+,%d1, addl %d1,%d0, tstb %d0". The advantage of RISC is that those extra instructions only take one clock cycle.

Tom

0 Kudos
1,143 Views
TomE
Specialist II

cfprm.pdf

ColdFire Family Programmer’s Reference Manual, Rev. 3

1.9.1 Organization of Integer Data Formats in Registers
Each integer data register is 32 bits wide. Byte and word operands occupy the lower 8- and 16-bit portions
of integer data registers, respectively. Longword operands occupy entire data registers. A data register that
is either a source or destination operand only uses or changes the appropriate lower 8 or 16 bits (in byte or
word operations, respectively). The remaining high-order portion does not change and is unused and unchanged.

The standard approach is to load the byte or word to a register, and then use EXT.W, EXT.L or EXTB.L as appropriate for signed data. Otherwise you can have to CLR.L the destination register first if you want unsigned.

Also remember a byte load or store on a register operates on the least-significant byte like you'd expect. Doing the same to a 32-bit value in memory and storing a byte to that stores in the UPPER byte. You have to use "address+3" to write to the lower one.

Tom

1,144 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

There is a training material about ColdFire core, which provide some info for your reference.

The memory organization with below types: byte, word and long word.

pastedImage_1.png

From the ColdFire programmer reference maual, MOVE intruction support opreation size: B, W, L,

pastedImage_2.png

Then I think MOVE intruction use Figure 2 to transfer byte data to register.

Thanks for the attention.

best regards,

Mike