44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package arm
|
|
|
|
// Jump continues program flow at the new offset.
|
|
func Jump(offset int) uint32 {
|
|
offset &= 0b11_1111_1111_1111_1111_1111_1111
|
|
return 0b000101<<26 | uint32(offset)
|
|
}
|
|
|
|
// JumpIfEqual jumps if the result was equal.
|
|
func JumpIfEqual(offset int) uint32 {
|
|
return branchCond(0b0000, offset)
|
|
}
|
|
|
|
// JumpIfNotEqual jumps if the result was not equal.
|
|
func JumpIfNotEqual(offset int) uint32 {
|
|
return branchCond(0b0001, offset)
|
|
}
|
|
|
|
// JumpIfGreater jumps if the result was greater.
|
|
func JumpIfGreater(offset int) uint32 {
|
|
return branchCond(0b1100, offset)
|
|
}
|
|
|
|
// JumpIfGreaterOrEqual jumps if the result was greater or equal.
|
|
func JumpIfGreaterOrEqual(offset int) uint32 {
|
|
return branchCond(0b1010, offset)
|
|
}
|
|
|
|
// JumpIfLess jumps if the result was less.
|
|
func JumpIfLess(offset int) uint32 {
|
|
return branchCond(0b1001, offset)
|
|
}
|
|
|
|
// JumpIfLessOrEqual jumps if the result was less or equal.
|
|
func JumpIfLessOrEqual(offset int) uint32 {
|
|
return branchCond(0b1101, offset)
|
|
}
|
|
|
|
// branchCond performs a conditional branch to a PC-relative offset.
|
|
func branchCond(cond uint32, offset int) uint32 {
|
|
offset &= 0b111_1111_1111_1111_1111
|
|
return 0b01010100<<24 | uint32(offset)<<5 | cond
|
|
}
|