SPARC Assembly Language Reference Manual

Chapter 5 Instruction-Set Mapping

The tables in this chapter describe the relationship between hardware instructions of the SPARC architecture, as defined in The SPARC Architecture Manual and the assembly language instruction set recognized by the SunOS 5.x SPARC assembler.

The SPARC-V9 instruction set is described in Appendix E, SPARC-V9 Instruction Set.

5.1 Table Notation

Table 5–1 shows the table notation used in this chapter to describe the instruction set of the assembler. The following notations are commonly suffixed to assembler mnemonics (uppercase letters refer to SPARC architecture instruction names.

Table 5–1

Notations 

Describes 

Comment 

address

regrs1 + regrs2

regrs1 + const13

regrs1 – const13

const13 + regrs1

const13

Address formed from register contents, immediate constant, or both. 

asi

 

Alternate address space identifier; an unsigned 8–bit value. It can be the result of the evaluation of a symbol expression. 

const13

 

A signed constant which fits in 13 bits. It can be the result of the evaluation of a symbol expression. 

const22

 

A constant which fits in 22 bits. It can be the result of the evaluation of a symbol expression. 

creg

%c0 ... %c31

Coprocessor registers. 

freg

%f0 ... %f31

Floating-point registers. 

imm7

 

A signed or unsigned constant that can be represented in 7 bits (it is in the range -64 ... 127). It can be the result of the evaluation of a symbol expression. 

reg

%r0 ... %r31

General purpose registers.  

 

%g0 ... %g7

Same as %r0 ... %r7 (Globals)

 

%o0 ... %o7

Same as %r8 ... %r15 (Outs)

 

%l0 ... %l7

Same as %r16 ... %r23 (Locals)

 

%i0 ... %i7

Same as %r24 ... %r31 (Ins)

regrd

 

Destination register. 

regrs1, regrs2

 

Source register 1, source register 2. 

reg_or_imm

regrs2, const13

Value from either a single register, or an immediate constant. 

regaddr

regrs1 regrs1 + regrs2

Address formed with register contents only. 

Software_trap_number

regrs1 + regrs2

regrs1 + imm7

regrs1 - imm7

uimm7

imm7 + regrs1

A value formed from register contents, immediate constant, or both. The resulting value must be in the range 0.....127, inclusive. 

uimm7

 

An unsigned constant that can be represented in 7 bits (it is in the range 0 ... 127). It can be the result of the evaluation of a symbol expression. 

5.2 Integer Instructions

The notations described in Table 5–2 are commonly suffixed to assembler mnemonics (uppercase letters for architecture instruction names).

Table 5–2

Notation 

Description 

a

Instructions that deal with alternate space 

b

Byte instructions 

c

Reference to coprocessor registers 

d

Doubleword instructions 

f

Reference to floating-point registers 

h

Halfword instructions 

q

Quadword instructions 

sr

Status register 

Table 5–3 outlines the correspondence between SPARC hardware integer instructions and SPARC assembly language instructions.

The syntax of individual instructions is designed so that a destination operand (if any), which may be either a register or a reference to a memory location, is always the last operand in a statement.


Note –

In Table 5–3,

"bgeu,a label"

Table 5–3

Opcode 

Mnemonic 

Argument List 

Operation 

Comments 

ADD

add

regrs1, reg_or_imm, regrd

Add 

 

ADDcc

addcc

regrs1, reg_or_imm, regrd

Add and modify icc

 

ADDX

addx

regrs1, reg_or_imm, regrd

Add with carry 

 

ADDXcc

addxcc

regrs1, reg_or_imm, regrd

 

 

AND

and

regrs1, reg_or_imm, regrd

And 

 

ANDcc

andcc

regrs1, reg_or_imm, regrd

 

 

ANDcc

andn

regrs1, reg_or_imm, regrd

 

 

ANDNcc

andcc

regrs1, reg_or_imm, regrd

 

 

BN

bn{,a}

label

Branch on integer condition codes 

branch never  

BNE

bne{,a}

label

 

synonym: bnz

BE

BG

BLE

BGE

BI

BGU

BLEU

be{,a}

bg{,a}

ble{,a}

bge{,a}

bl{,a}

bgu{,a}

bleu{,a}

label

label

label

label

label

label

label

 

synonym: bz

BCC

bcc{,a}

label

 

synonym: bgeu

BCS

BPOS

BNEG

BVC

BVS

bcs{,a}

bpos{,a}

bneg{,a}

bvc{,a}

bvs{,a}

label

label

label

label

label

 

synonym: blu

BA

ba{,a}

label

 

synonym: b

CALL

call

label

Call subprogram 

 

CBccc

cbn{,a}

cb3{,a}

cb2{,a}

cb23{,a}

cb1{,a}

cb13{,eo}

cb12{,a}

cb123{,a}

cb0{,a}

cb03{,a}

cb02{,a}

cb023{,a}

cb01{,a}

cb013{,a}

cb012{,a}

cba{,a}

label

label

label

label

label

label

label

label

label

label

label

label

label

label

label

label

Branch on coprocessor condition codes 

branch never 

FBN

FBU

FBG

FBUG

FBL

FBUL

FBLG

fbn{,a}

fbu{,a}

fbg{,a}

fbug{,a}

fbl{,a}

fbul{,a}

fblg{,a}

label

label

label

label

label

label

label

Branch on floating-point condition codes 

branch never  

FBNE

fbne{,a}

label

 

synonym: fbnz

FBE

fbe{,a}

label

 

synonym: fbz

FBUE

FBGE

FBUGE

FBLE

FBULE

FBO

FBA

fbue{,a}

fbge{,a}

fbuge{,a}

fble{,a}

fbule{,a}

fbo{,a}

fba{,a}

label

label

label

label

label

label

label

 

 

FLUSH

flush

address

Instruction cache flush

 

JMPL

jmpl

address, regrd

Jump and link 

 

LDSB

ldsb

[address], regrd

Load signed byte 

 

LDSH

ldsh

[address], regrd

Load signed halfword 

 

LDSTUB

ldstub

[address], regrd

Load-store unsigned byte 

 

LDUB

ldub

[address], regrd

Load unsigned byte 

 

LDUH

lduh

[address], regrd

Load unsigned halfword 

 

LD

ld

[address], regrd

Load word 

 

LDD

ldd

[address], regrd

Load double word 

regrd must be even

LDF

ld

[address], fregrd

 

 

LDFSR

ld

[address], %fsr

Load floating-point register 

 

LDDF

ldd

[address], fregrd

Load double floating-point 

fregrd must be even

LDC

ld

[address], cregrd

Load coprocessor 

 

LDCSR

ld

[address], %csr

Load double coprocessor 

 

LDDC

ldd

[address], cregrd

 

 

LDSBA

LDSHA

LDUBA

LDUHA

LDA

ldsba

ldsha

lduba

lduha

lda

[regaddr]asi, regrd

[regaddr]asi, regrd

[regaddr]asi, regrd

[regaddr]asi, regrd

[regaddr]asi, regrd

Load signed byte from alternate space 

 

LDDA

ldda

[regaddr]asi, regrd

 

regrd must be even

LDSTUBA

ldstuba

[regaddr]asi, regrd

 

 

MULScc

mulscc

regrs1, reg_or_imm, regrd

Multiply step (and modify icc)

 

NOP

nop

 

No operation 

 

OR

ORcc

ORN

ORNcc

or

orcc

orn

orncc

regrs1, reg_or_imm, regrd

regrs1, reg_or_imm, regrd

regrs1, reg_or_imm, regrd

regrs1, reg_or_imm, regrd

Inclusive or

 

RDASR

rd

%asrnrs1, regrd

 

 

RDY

rd

%y, regrd

 

See synthetic instructions. 

RDPSR

rd

%psr, regrd

 

See synthetic instructions. 

RDWIM

rd

%wim, regrd

 

See synthetic instructions. 

RDTBR

rd

%tbr, regrd

 

See synthetic instructions. 

RESTORE

restore

regrs1, reg_or_imm, reg rd

 

See synthetic instructions. 

RETT

rett

address

Return from trap 

 

SAVE

save

regrs1, reg_or_imm, regrd

 

See synthetic instructions. 

SDIV

sdiv

regrs1, reg_or_imm, regrd

Signed divide 

 

SDIVcc

sdivcc

regrs1, reg_or_imm, regrd

Signed divide and modify icc

 

SMUL

smul

regrs1, reg_or_imm, regrd

Signed multiply 

 

SMULcc

smulcc

regrs1, reg_or_imm, regrd

Signed multiply and modify icc

 

SETHI

sethi

const22, regrd

Set high 22 bits of register 

 

sethi

%hi(value), regrd

 

See synthetic instructions. 

SLL

sll

regrs1, reg_or_imm, regrd

Shift left logical 

 

SRL

srl

regrs1, reg_or_imm, regrd

Shift right logical 

 

SRA

sra

regrs1, reg_or_imm, regrd

Shift right arithmetic 

 

STB

stb

regrd, [address]

Store byte  

Synonyms: stub, stsb

STH

sth

regrd, [address]

Store half-word  

Synonyms: stuh, stsh

ST

st

regrd, [address]

 

 

STD

std

regrd, [address]

 

regrd Must be even

STF

st

fregrd, [address]

 

 

STDF

std

fregrd, [address]

 

 

STFSR

st

%fsr, [address]

Store floating-point status register 

fregrd Must be even

STDFQ

std

%fq, [address]

Store double floating-point queue 

 

STC

st

cregrd, [address]

Store coprocessor 

cregrd Must be even

STDC

std

cregrd, [address]

 

cregrd Must be even

STCSR

st

%csr, [address]

 

 

STDCQ

std

%cq, [address]

Store double coprocessor  

 

STBA

stba

regrd [regaddr]asi

Store byte into alternate space 

Synonyms: stuba, stsba 

STHA

stha

regrd [regaddr]asi

 

Synonyms: stuha, stsha 

STA

sta

regrd, [regaddr]asi

 

 

STDA

stda

regrd, [regaddr]asi

 

regrd Must be even

SUB

sub

regrs1, reg_or_imm, regrd

Subtract 

 

SUBcc

subcc

regrs1, reg_or_imm, regrd

Subtract and modify icc

 

SUBX

subx

regrs1, reg_or_imm, regrd

Subtract with carry 

 

SUBXcc

subxcc

regrs1, reg_or_imm, regrd

 

 

SWAP

SWAPA

swap

swapa

[address], regrd

[regaddr]asi, regrd

Swap memory word 

with register 

 

Ticc

tn

software_trap_number

Trap on integer condition code 

Trap never  

tne

software_trap_number

Note: Trap numbers 16-31 are reserved for the user. Currently-defined trap numbers are those defined in /usr/include/sys/trap.h

 

Synonym: tnz

 

te

tg

tle

tge

tl

tgu

software_trap_number

software_trap_number

software_trap_number

software_trap_number

software_trap_number

software_trap_number

 

Synonym: tz

 

tleu

software_trap_number

 

Synonym: tcc

 

tlu

tgeu

tpos

tneg

software_trap_number

software_trap_number

software_trap_number

software_trap_number

 

Synonym: tcc

 

tvc

tvs

ta

software_trap_number

software_trap_number

software_trap_number

 

Synonym: t

TADDcc

TSUBcc

taddcc

tsubcc

regrs1, reg_or_imm, regrd

regrs1, reg_or_imm, regrd

Tagged add and modify icc

 

TADDccTV

TSUBccTV

taddcctv

tsubcctv

regrs1, reg_or_imm, regrd

regrs1, reg_or_imm, regrd

Tagged add and modify icc and trap on overflow

 

UDIV

udiv

regrs1, reg_or_imm, regrd

Unsigned divide 

 

UDIVcc

udivcc

regrs1, reg_or_imm, regrd

Unsigned divide and modify icc

 

UMUL

umul

regrs1, reg_or_imm, regrd

Unsigned multiply 

 

UMULcc

umulcc

regrs1, reg_or_imm, regrd

Unsigned multiply and modify icc

 

UNIMP

unimp

const22

Illegal instruction 

 

WRASR

wr

reg_or_imm, %asrnrs1

 

 

WRY

wr

regrs1, reg_or_imm, %y

 

See synthetic instructions 

WRPSR

wr

regrs1, reg_or_imm, %psr

 

See synthetic instructions 

WRWIM

wr

regrs1, reg_or_imm, %wim

 

See synthetic instructions 

WRTBR

wr

regrs1, reg_or_imm, %tbr

 

See synthetic instructions 

XNOR

XNORcc

xnor

xnorcc

regrs1, reg_or_imm, regrd

regrs1, reg_or_imm, regrd

Exclusive nor

 

XOR

XORcc

xor

xorcc

regrs1, reg_or_imm, regrd

regrs1, reg_or_imm, regrd

Exclusive or

 

5.3 Floating-Point Instruction

Table 5–4 shows floating-point instructions. In cases where more than numeric type is involved, each instruction in a group is described; otherwise, only the first member of a group is described.

Table 5–4

SPARC 

Mnemonic [Types of Operands are denoted by the following lower-case letters:i integers singled doubleq quad]

Argument List 

Description 

FiTOs

fitos

fregrs2, fregrd

Convert integer to single 

FiTOd

fitod

fregrs2, fregrd

Convert integer to double 

FiTOq

fitoq

fregrs2, fregrd

Convert integer to quad 

FsTOi

fstoi

fregrs2, fregrd

Convert single to integer 

FdTOi

fdtoi

fregrs2, fregrd

Convert double to integer 

FqTOi

fqtoi

fregrs2, fregrd

Convert quad to integer 

FsTOd

fstod

fregrs2, fregrd

Convert single to double 

FsTOq

fstoq

fregrs2, fregrd

Convert single to quad 

FdTOs

fdtos

fregrs2, fregrd

Convert double to single 

FdTOq

fdtoq

fregrs2, fregrd

Convert double to quad 

FqTOd

fqtod

fregrs2, fregrd

Convert quad to double 

FqTOs

fqtos

fregrs2, fregrd

Convert quad to single 

FMOVs

fmovs

fregrs2, fregrd

Move 

FNEGs

fnegs

fregrs2, fregrd

Negate 

FABSs

fabss

fregrs2, fregrd

Absolute value 

FSQRTs

FSQRTd

FSQRTq

fsqrts

fsqrtd

fsqrtq

fregrs2, fregrd

fregrs2, fregrd

fregrs2, fregrd

Square root 

FADDs

FADDd

FADDq

fadds

faddd

faddq

fregrs1, fregrs2, fregrd

fregrs1, fregrs2, fregrd

fregrs1, fregrs2, fregrd

Add 

FSUBs

FSUBd

FSUBq

fsubs

fsubd

fsubq

fregrs1, fregrs2, fregrd

fregrs1, fregrs2, fregrd

fregrs1, fregrs2, fregrd

Subtract 

FMULs

FMULd

FMULq

fmuls

fmuld

fmulq

fregrs1, fregrs2, fregrd

fregrs1, fregrs2, fregrd

fregrs1, fregrs2, fregrd

Multiply 

FdMULq

fmulq

fregrs1, fregrs2, fregrd

Multiply double to quad 

FsMULd

fsmuld

fregrs1, fregrs2, fregrd

Multiply single to double 

FDIVs

FDIVd

FDIVq

fdivs

fdivd

fdivq

fregrs1, fregrs2, fregrd

fregrs1, fregrs2, fregrd

fregrs1, fregrs2, fregrd

Divide 

FCMPs

FCMPd

FCMPq

fcmps

fcmpd

fcmpq

fregrs1, fregrs2

fregrs1, fregrs2

fregrs1, fregrs2

Compare 

FCMPEs

FCMPEd

FCMPEq

fcmpes

fcmped

fcmpeq

fregrs1, fregrs2

fregrs1, fregrs2

fregrs1, fregrs2

Compare, generate exception if not ordered 

5.4 Coprocessor Instructions

All coprocessor-operate (cpopn) instructions take all operands from and return all results to coprocessor registers. The data types supported by the coprocessor are coprocessor-dependent. Operand alignment is also coprocessor-dependent. Coprocessor-operate instructions are described in Table 5–5.

If the EC (PSR_enable_coprocessor) field of the processor state register (PSR) is 0, or if a coprocessor is not present, a cpopn instruction causes a cp_disabled trap.

The conditions that cause a cp_exception trap are coprocessor-dependent.

Table 5–5

SPARC 

Mnemonic 

Argument List 

Name 

Comments 

CPop1

cpop1

opc, regrs1, regrs2, regrd

Coprocessor operation 

 

CPop2

cpop2

opc, regrs1, regrs2, regrd

Coprocessor operation 

May modify ccc

5.5 Synthetic Instructions

Table 5–6 describes the mapping of synthetic instructions to hardware instructions.

Table 5–6

Synthetic Instruction 

Hardware Equivalent(s) 

Comment 

btst

reg_or_imm, regrs1

andcc

regrs1, reg_or_imm, %g0

Bit test 

bset

reg_or_imm, regrd

or

regrd, reg_or_imm, regrd

Bit set 

bclr

reg_or_imm, regrd

andn

regrd, reg_or_imm, regrd

Bit clear 

btog

reg_or_imm, regrd

xor

regrd, reg_or_imm, regrd

Bit toggle 

call

reg_or_imm

jmpl

reg_or_imm, %o7

 

clr

regrd

or

%g0, %g0, regrd

Clear (zero) register 

clrb

[address]

stb

%g0, [address]

Clear byte 

clrh

[address]

st

%g0, [address]

Clear halfword 

clr

[address]

st

%g0, [address]

Clear word 

cmp

reg, reg_or_imm

subcc

regrs1, reg_or_imm, %g0

Compare 

dec

regrd

sub

regrd, 1, regrd

Decrement by 1 

dec

const13, regrd

sub

regrd, const13, regrd

Decrement by const13

deccc

regrd

subcc

regrd, 1, regrd

Decrement by 1 and set icc

deccc

const13, regrd

subcc

regrd, const13, regrd

Decrement by const13 and set icc

inc

regrd

add

regrd, 1, regrd

Increment by 1 

inc

const13, regrd

add

regrd, const13, regrd

Increment by const13

inccc

regrd

addcc

regrd, 1, regrd

Increment by 1 and set icc

inccc

const13, regrd

addcc

regrd, const13, regrd

Increment by const13 and set icc

jmp

address

jmpl

address, %g0

 

mov

mov

mov

mov

mov

mov

mov

mov

mov

reg_or_imm,regrd

%y, regrs1

%psr, regrs1

%wim, regrs1

%tbr, regrs1

reg_or_imm, %y

reg_or_imm, %psr

reg_or_imm, %wim

reg_or_imm, %tbr

or

rd

rd

rd

rd

wr

wr

wr

wr

%g0, reg_or_imm, regrd

%y, regrs1

%psr, regrs1

%wim, regrs1

%tbr, regrs1

%g0,reg_or_imm,%y

%g0,reg_or_imm,%psr

%g0,reg_or_imm,%wim

%g0,reg_or_imm,%tbr

 

not

regrs1, regrd

xnor

regrs1, %g0, regrd

One's complement 

not

regrd

xnor

regrd, %g0, regrd

One's complement 

neg

regrs1, regrd

sub

%g0, regrs2, regrd

Two's complement 

neg

regrd

sub

%g0, regrd, regrd

Two's complement 

restore

 

restore

%g0, %g0, %g0

Trivial restore

save

 

save

%g0, %g0, %g0

Trivial save

trivial save should only be used in supervisor code!

set

value,regrd

or

%g0, value, regrd

if -4096 ≤value ≤ 4095

Do not use the set synthetic instruction in an instruction delay slot.

set

value,regrd

sethi

%hi(value), regrd

if ((value & 0x3ff) == 0)

set

value, regrd

sethi

or

%hi(value), regrd; regrd, %lo(value), regrd

otherwise 

Do not use the set synthetic instruction in an instruction delay slot.

skipz

 

bnz,a .+8

 

if z is set, ignores next instruction

skipnz

 

bz,a .+8

 

if z is not set, ignores next instruction

tst

reg

orcc

regrs1, %g0, %g0

test 

5.6 V8/V9 Natural Pseudo Instructions

Table 5–7 describes the V8/V9 natural pseudo instructions that will help increase the portability of your assembly code from V8/V8plus to V9.

Table 5–7

Pseudo Instructions  

-xarch= 

V8/V8plus [Indicates default setting]

V9 

ldn

ld 

ldx 

stn

st

stx 

ldna

lda 

ldxa 

stna

sta

stxa 

setn

set 

setx

setnhi 

sethi 

setxhi 

casn 

cas 

casx 

slln 

sll 

sllx 

srln 

srl 

srlx 

sran 

sra 

srax 

clrn 

clr 

clrx 


Note –

Depending on the value set for the -xarch option, the assembler substitutes the appropriate pseudo instruction.