1

I know this question has been asked before so sorry to ask again but I have no clue how to fix it. At the start of my program I try to move binary value 101000110000100110000 into R0 but I get the error message "Error: invalid constant (146130) after fixup"

        .global _start
_start: 
    mov R0,#0b101000110000100110000
    bl  correct16
    mov R7,#1
    svc 0

correct16:
    push    {R1-R10}

I don't really understand why it is doing this or how to fix it because I have never had this error before.

Tudders
  • 53
  • 8
  • 2
    Consult an instruction set reference, in particular the allowed range of immediates for a `mov`. TL;DR: use `ldr r0, =0b101000110000100110000` PS: next time specify which assembler you are using – Jester Apr 23 '19 at 14:36
  • Possible duplicate of [Invalid constant after fixup?](https://stackoverflow.com/questions/10261300/invalid-constant-after-fixup) – Sean Houlihane Apr 24 '19 at 12:25

1 Answers1

4

You're trying to use an immediate value of 0x146130, the mov instruction can take an immediate up to 16 bits (though this depends on your architecture and instruction set), so what you're attempting to do can't be encoded. You can load a 16 bit immediate, and add the rest in, or use a literal pool to solve it.

_start: 
    mov R0,#0x6130       
    movt R0,#0x14
    bl  correct16
    mov R7,#1
    svc 0

This loads the bottom halfword into r0, then loads in the top halfword afterwards.

Colin
  • 3,394
  • 1
  • 21
  • 29