Next: M32R-Warnings, Previous: M32R-Opts, Up: M32R-Dependent

#### 8.19.2 M32R Directives

The Renease M32R version of `as` has a few architecture specific directives:

`low` expression
  The `low` directive computes the value of its expression and places the lower 16-bits of the result into the immediate-field of the instruction. For example:

                   or3   r0, r0, #low(0x12345678) ; compute r0 = r0 | 0x5678
                   add3, r0, r0, #low(fred)   ; compute r0 = r0 + low 16-bits of address of fred

`high` expression
  The `high` directive computes the value of its expression and places the upper 16-bits of the result into the immediate-field of the instruction. For example:

                   seth  r0, #high(0x12345678) ; compute r0 = 0x12340000
                   seth, r0, #high(fred)       ; compute r0 = upper 16-bits of address of fred

`shigh` expression
  The `shigh` directive is very similar to the `high` directive. It also computes the value of its expression and places the upper 16-bits of the result into the immediate-field of the instruction. The difference is that `shigh` also checks to see if the lower 16-bits could be interpreted as a signed number, and if so it assumes that a borrow will occur from the upper-16 bits. To compensate for this the `shigh` directive pre-biases the upper 16 bit value by adding one to it. For example:

  For example:

                   seth  r0, #shigh(0x12345678) ; compute r0 = 0x12340000
                   seth  r0, #shigh(0x00008000) ; compute r0 = 0x00010000

  In the second example the lower 16-bits are 0x8000. If these are treated as a signed value and sign extended to 32-bits then the value becomes 0xffff8000. If this value is then added to 0x00010000 then the result is 0x00008000.

  This behaviour is to allow for the different semantics of the `or3` and `add3` instructions. The `or3` instruction treats its 16-bit immediate argument as unsigned whereas the `add3` treats its 16-bit immediate as a signed value. So for example:

                   seth  r0, #shigh(0x00008000)
                   add3  r0, r0, #low(0x00008000)

  Produces the correct result in r0, whereas:

                   seth  r0, #shigh(0x00008000)
                   or3   r0, r0, #low(0x00008000)

  Stores 0xffff8000 into r0.

  Note - the `shigh` directive does not know where in the assembly source code the lower 16-bits of the value are going set, so it cannot check to make sure that an `or3` instruction is being used rather than an `add3` instruction. It is up to the programmer to make sure that correct directives are used.

`.m32r`
  The directive performs a similar thing as the -m32r command line option. It tells the assembler to only accept M32R instructions from now on. An instructions from later M32R architectures are refused.

`.m32rx`
  The directive performs a similar thing as the -m32rx command line option. It tells the assembler to start accepting the extra instructions in the M32RX ISA as well as the ordinary M32R ISA.

`.m32r2`
  The directive performs a similar thing as the -m32r2 command line option. It tells the assembler to start accepting the extra instructions in the M32R2 ISA as well as the ordinary M32R ISA.

`.little`
  The directive performs a similar thing as the -little command line option. It tells the assembler to start producing little-endian code and data. This option should be used with care as producing mixed-endian binary files is fraught with danger.

`.big`
  The directive performs a similar thing as the -big command line option. It tells the assembler to start producing big-endian code and data. This option should be used with care as producing mixed-endian binary files is fraught with danger.