aboutsummaryrefslogtreecommitdiff
path: root/opcodes/mep-ibld.c
diff options
context:
space:
mode:
Diffstat (limited to 'opcodes/mep-ibld.c')
-rw-r--r--opcodes/mep-ibld.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/opcodes/mep-ibld.c b/opcodes/mep-ibld.c
index d1e33fa..0faf948 100644
--- a/opcodes/mep-ibld.c
+++ b/opcodes/mep-ibld.c
@@ -207,12 +207,19 @@ insert_normal (CGEN_CPU_DESC cd,
#if CGEN_INT_INSN_P
{
- int shift;
+ int shift_within_word, shift_to_word, shift;
+ /* How to shift the value to BIT0 of the word. */
+ shift_to_word = total_length - (word_offset + word_length);
+
+ /* How to shift the value to the field within the word. */
if (CGEN_INSN_LSB0_P)
- shift = (word_offset + start + 1) - length;
+ shift_within_word = start + 1 - length;
else
- shift = total_length - (word_offset + start + length);
+ shift_within_word = word_length - start - length;
+
+ /* The total SHIFT, then mask in the value. */
+ shift = shift_to_word + shift_within_word;
*buffer = (*buffer & ~(mask << shift)) | ((value & mask) << shift);
}