Clemson University -- CPSC 231 -- Fall 2009 Instruction formats formats are basically rules on how bit patterns are interpreted/decoded a format specifies the positions of fields such as opcodes, register identifiers, and constants format 1: call +--+----------------------------------+ bit encoding is |01|.......30-bit displacement........| +--+----------------------------------+ format 2: +--+-----+---+------------------------+ sethi is |00|rdest|100|..22-bit displacement...| +--+-+---+---+------------------------+ branch is |00|a|cnd|op2|..22-bit displacement...| +--+-+---+---+------------------------+ "a" is the annul bit, if set then the instruction in the delay slot of the branch is executed only if the branch is taken (thus you can move the first instruction from the branch target into the delay slot without causing incorrect values when the branch is untaken) format 3: +--+-----+------+-----+-+--------+-----+ 3-register is |1x|rdest|.op3..|rsrc1|0|asi/fpop|rsrc2| +--+-----+------+-----+-+--------+-----+ immediate is |1x|rdest|.op3..|rsrc1|1|signed 13-bit | +--+-----+------+-----+-+--------------+ note that calls and branches are pc-relative, this makes it easier to link and load programs Loading a 32-bit constant/address sethi instruction takes 22-bit constant and loads it into a register after shifting to the left by 10 places, thus you can get the rest of a 32-bit constant by or-ing in the low ten bits pseudo-ops %hi(a) == a >> 10 %lo(a) == a & 0x3ff set 0x12345678, %o0 == sethi %hi(0x12345678), %o0 or %o0, %lo(0x12345678), %o0 loading a non-stack value from memory given a label set x_m, %o0 ! expands into two instructions: sethi and or ld [%o0], %o1 alternatively, the or can be included as part of the addressing mode sethi %hi(x_m), %o0 ld [%o0 + %lo(x_m)], %o1 since set, %hi(), and %lo() often deal with absolute addresses, rather than pc-relative, the argument is limited to a symbol +/- small constant