Added push and pop instructions
This commit is contained in:
parent
8e64271f74
commit
735057ac74
@ -91,6 +91,18 @@ func (a *Assembler) Finalize() ([]byte, []byte) {
|
|||||||
code = x64.MoveRegisterRegister64(code, operands.Destination, operands.Source)
|
code = x64.MoveRegisterRegister64(code, operands.Destination, operands.Source)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case POP:
|
||||||
|
switch operands := x.Data.(type) {
|
||||||
|
case *Register:
|
||||||
|
code = x64.PopRegister(code, operands.Register)
|
||||||
|
}
|
||||||
|
|
||||||
|
case PUSH:
|
||||||
|
switch operands := x.Data.(type) {
|
||||||
|
case *Register:
|
||||||
|
code = x64.PushRegister(code, operands.Register)
|
||||||
|
}
|
||||||
|
|
||||||
case RETURN:
|
case RETURN:
|
||||||
code = x64.Return(code)
|
code = x64.Return(code)
|
||||||
|
|
||||||
|
@ -24,6 +24,16 @@ func (a *Assembler) RegisterRegister(mnemonic Mnemonic, left cpu.Register, right
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register adds an instruction using a single register.
|
||||||
|
func (a *Assembler) Register(mnemonic Mnemonic, register cpu.Register) {
|
||||||
|
a.Instructions = append(a.Instructions, Instruction{
|
||||||
|
Mnemonic: mnemonic,
|
||||||
|
Data: &Register{
|
||||||
|
Register: register,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Label adds a label at the current position.
|
// Label adds a label at the current position.
|
||||||
func (a *Assembler) Label(name string) {
|
func (a *Assembler) Label(name string) {
|
||||||
a.Instructions = append(a.Instructions, Instruction{
|
a.Instructions = append(a.Instructions, Instruction{
|
||||||
|
@ -11,6 +11,8 @@ const (
|
|||||||
MUL
|
MUL
|
||||||
LABEL
|
LABEL
|
||||||
MOVE
|
MOVE
|
||||||
|
POP
|
||||||
|
PUSH
|
||||||
RETURN
|
RETURN
|
||||||
SUB
|
SUB
|
||||||
SYSCALL
|
SYSCALL
|
||||||
@ -40,6 +42,12 @@ func (m Mnemonic) String() string {
|
|||||||
case MUL:
|
case MUL:
|
||||||
return "mul"
|
return "mul"
|
||||||
|
|
||||||
|
case POP:
|
||||||
|
return "pop"
|
||||||
|
|
||||||
|
case PUSH:
|
||||||
|
return "push"
|
||||||
|
|
||||||
case RETURN:
|
case RETURN:
|
||||||
return "return"
|
return "return"
|
||||||
|
|
||||||
|
15
src/build/asm/Register.go
Normal file
15
src/build/asm/Register.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package asm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.akyoto.dev/cli/q/src/build/cpu"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Register operates with a single register.
|
||||||
|
type Register struct {
|
||||||
|
Register cpu.Register
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a human readable version.
|
||||||
|
func (data *Register) String() string {
|
||||||
|
return data.Register.String()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user