Jump to content

SPARC Assembly/Control Flow

From Wikibooks, open books for an open world

Comparison

[edit | edit source]
Instruction:
cmp

compares two numbers (Subtraction). Sets flags.

Instruction:
tst

tests two numbers (performs 'and' operation). Sets flags.

Jump Instructions

[edit | edit source]
Instruction:
jmp

jumps to specified indirect address. stores return address in %o7.

Instruction:
jmpl

Performs an unconditional, register indirect jump. Target address is provided in the first operand, and the return address is then stored into the rd operand.

jmpl rs1, rd

If the return address is stored in %o7, this acts like a subroutine call. If the return address is stored in %g0, it acts like a subroutine return.

Instruction:
sethi

Sets the highest 22 bits of the target register, sets the lowest 10 bits to zero.

sethi const22, rd

const22 must be a constant value, cannot be a register.

Subroutine Instructions

[edit | edit source]
Instruction:
call

calls a subroutine. Takes a single label as a new target address. Stores the return address in %o7. cannot jump to a register indirect address.

Instruction:
ret

return from a subroutine.

Instruction:
retl

return from a leaf subroutine.

Instruction:
rett

Return from a trap instruction, or from a register indirect control transfer.

Instruction:
save

saves the current register window and creates a new window. raises an exception if there is a register window overflow.

Instruction:
restore

restores a saved register window.

Branch Instructions

[edit | edit source]

branches do not store the return address.

Instruction:
ba

Branch always. an unconditional jump to the target location. d

Instruction:
bn

Branch never.

Instruction:
be
Instruction:
bne

branches if the two operands are equal or not equal, respectively.

Instruction:
bl

branches on "less than"

Instruction:
ble

branches on "less than or equal"

Instruction:
bge

branches on "greater than or equal"

Instruction:
bg

branches on "greater than"

Instruction:
blu
Instruction:
bleu

Same as bl and ble, except uses unsigned numbers

Instruction:
bgeu
Instruction:
bgu

Same as bge and bg, except uses unsigned numbers

Instruction:
bpos

branches if the number is positive.

Instruction:
bneg

branches if the number is negative.

Instruction:
bcs
Instruction:
bcc

branches if the carry bit is set or clear, respectively.

Instruction:
bvs
Instruction:
bvc

branches if the signed overflow bit is set or clear, respectively.