Improved function names
This commit is contained in:
parent
37e222e022
commit
871ebc147f
19 changed files with 94 additions and 114 deletions
|
@ -4,39 +4,12 @@ import (
|
|||
"git.akyoto.dev/cli/q/src/build/cpu"
|
||||
)
|
||||
|
||||
// AddRegNum adds a number to the given register.
|
||||
func AddRegNum(code []byte, destination cpu.Register, number int) []byte {
|
||||
return numRegReg(code, 0, byte(destination), number, 0x83, 0x81)
|
||||
// AddRegisterNumber adds a number to the given register.
|
||||
func AddRegisterNumber(code []byte, destination cpu.Register, number int) []byte {
|
||||
return regRegNum(code, 0, byte(destination), number, 0x83, 0x81)
|
||||
}
|
||||
|
||||
// AddRegReg adds a number to the given register.
|
||||
func AddRegReg(code []byte, destination cpu.Register, operand cpu.Register) []byte {
|
||||
// AddRegisterRegister adds a register value into another register.
|
||||
func AddRegisterRegister(code []byte, destination cpu.Register, operand cpu.Register) []byte {
|
||||
return regReg(code, byte(operand), byte(destination), 0x01)
|
||||
}
|
||||
|
||||
func regReg(code []byte, reg byte, rm byte, opCodes ...byte) []byte {
|
||||
w := byte(1) // Indicates a 64-bit register.
|
||||
r := byte(0) // Extension to the "reg" field in ModRM.
|
||||
x := byte(0) // Extension to the SIB index field.
|
||||
b := byte(0) // Extension to the "rm" field in ModRM or the SIB base (r8 up to r15 use this).
|
||||
mod := byte(0b11) // Direct addressing mode, no register offsets.
|
||||
|
||||
if reg > 0b111 {
|
||||
r = 1
|
||||
reg &= 0b111
|
||||
}
|
||||
|
||||
if rm > 0b111 {
|
||||
b = 1
|
||||
rm &= 0b111
|
||||
}
|
||||
|
||||
rex := REX(w, r, x, b)
|
||||
modRM := ModRM(mod, reg, rm)
|
||||
|
||||
code = append(code, rex)
|
||||
code = append(code, opCodes...)
|
||||
code = append(code, modRM)
|
||||
|
||||
return code
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue