Implemented bitwise operations

This commit is contained in:
2024-07-25 14:17:51 +02:00
parent b8900b518a
commit d1a8f0d66c
12 changed files with 287 additions and 5 deletions

15
src/build/arch/x64/And.go Normal file
View File

@ -0,0 +1,15 @@
package x64
import (
"git.akyoto.dev/cli/q/src/build/cpu"
)
// AndRegisterNumber performs a bitwise AND using a register and a number.
func AndRegisterNumber(code []byte, destination cpu.Register, number int) []byte {
return encodeNum(code, AddressDirect, 0b100, destination, number, 0x83, 0x81)
}
// AndRegisterRegister performs a bitwise AND using two registers.
func AndRegisterRegister(code []byte, destination cpu.Register, operand cpu.Register) []byte {
return encode(code, AddressDirect, operand, destination, 8, 0x21)
}

15
src/build/arch/x64/Or.go Normal file
View File

@ -0,0 +1,15 @@
package x64
import (
"git.akyoto.dev/cli/q/src/build/cpu"
)
// OrRegisterNumber performs a bitwise OR using a register and a number.
func OrRegisterNumber(code []byte, destination cpu.Register, number int) []byte {
return encodeNum(code, AddressDirect, 0b001, destination, number, 0x83, 0x81)
}
// OrRegisterRegister performs a bitwise OR using two registers.
func OrRegisterRegister(code []byte, destination cpu.Register, operand cpu.Register) []byte {
return encode(code, AddressDirect, operand, destination, 8, 0x09)
}

15
src/build/arch/x64/Xor.go Normal file
View File

@ -0,0 +1,15 @@
package x64
import (
"git.akyoto.dev/cli/q/src/build/cpu"
)
// XorRegisterNumber performs a bitwise XOR using a register and a number.
func XorRegisterNumber(code []byte, destination cpu.Register, number int) []byte {
return encodeNum(code, AddressDirect, 0b110, destination, number, 0x83, 0x81)
}
// XorRegisterRegister performs a bitwise XOR using two registers.
func XorRegisterRegister(code []byte, destination cpu.Register, operand cpu.Register) []byte {
return encode(code, AddressDirect, operand, destination, 8, 0x31)
}