Implemented register to register instructions
This commit is contained in:
parent
1c27f0cad2
commit
a9d43a8716
11 changed files with 171 additions and 16 deletions
|
@ -28,8 +28,13 @@ func (a *Assembler) Finalize() ([]byte, []byte) {
|
|||
for _, x := range a.Instructions {
|
||||
switch x.Mnemonic {
|
||||
case MOVE:
|
||||
regNum := x.Data.(*RegisterNumber)
|
||||
code = x64.MoveRegNum32(code, uint8(regNum.Register), uint32(regNum.Number))
|
||||
switch operands := x.Data.(type) {
|
||||
case *RegisterNumber:
|
||||
code = x64.MoveRegNum32(code, operands.Register, uint32(operands.Number))
|
||||
|
||||
case *RegisterRegister:
|
||||
code = x64.MoveRegReg64(code, operands.Destination, operands.Source)
|
||||
}
|
||||
|
||||
case RETURN:
|
||||
code = x64.Return(code)
|
||||
|
|
|
@ -13,6 +13,17 @@ func (a *Assembler) MoveRegisterNumber(reg cpu.Register, number uint64) {
|
|||
})
|
||||
}
|
||||
|
||||
// MoveRegisterRegister moves a register value into another register.
|
||||
func (a *Assembler) MoveRegisterRegister(destination cpu.Register, source cpu.Register) {
|
||||
a.Instructions = append(a.Instructions, Instruction{
|
||||
Mnemonic: MOVE,
|
||||
Data: &RegisterRegister{
|
||||
Destination: destination,
|
||||
Source: source,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Label adds a label at the current position.
|
||||
func (a *Assembler) Label(name string) {
|
||||
a.Instructions = append(a.Instructions, Instruction{
|
||||
|
|
18
src/build/asm/RegisterRegister.go
Normal file
18
src/build/asm/RegisterRegister.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
package asm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/build/cpu"
|
||||
)
|
||||
|
||||
// RegisterRegister operates with two registers.
|
||||
type RegisterRegister struct {
|
||||
Destination cpu.Register
|
||||
Source cpu.Register
|
||||
}
|
||||
|
||||
// String returns a human readable version.
|
||||
func (data *RegisterRegister) String() string {
|
||||
return fmt.Sprintf("%s, %s", data.Destination, data.Source)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue