q/src/x86/StoreDynamic.go
2025-02-05 23:16:18 +01:00

27 lines
938 B
Go

package x86
import (
"encoding/binary"
"git.akyoto.dev/cli/q/src/cpu"
)
// StoreDynamicNumber stores a number into the memory address at `destination` with a register offset.
func StoreDynamicNumber(code []byte, destination cpu.Register, offset cpu.Register, length byte, number int) []byte {
code = memoryAccessDynamic(code, 0xC6, 0xC7, destination, offset, length, 0b000)
switch length {
case 8, 4:
return binary.LittleEndian.AppendUint32(code, uint32(number))
case 2:
return binary.LittleEndian.AppendUint16(code, uint16(number))
}
return append(code, byte(number))
}
// StoreDynamicRegister stores the contents of the `source` register into the memory address at `destination` with a register offset.
func StoreDynamicRegister(code []byte, destination cpu.Register, offset cpu.Register, length byte, source cpu.Register) []byte {
return memoryAccessDynamic(code, 0x88, 0x89, destination, offset, length, source)
}