Implemented if statements
This commit is contained in:
parent
c139dced9e
commit
962a362578
16 changed files with 280 additions and 14 deletions
|
@ -66,8 +66,32 @@ func (a Assembler) Finalize() ([]byte, []byte) {
|
|||
case COMMENT:
|
||||
continue
|
||||
|
||||
case JUMP:
|
||||
code = x64.Jump8(code, 0x00)
|
||||
case COMPARE:
|
||||
switch operands := x.Data.(type) {
|
||||
case *RegisterNumber:
|
||||
code = x64.CompareRegisterNumber(code, operands.Register, operands.Number)
|
||||
case *RegisterRegister:
|
||||
code = x64.CompareRegisterRegister(code, operands.Destination, operands.Source)
|
||||
}
|
||||
|
||||
case JUMP, JE, JNE, JG, JL, JGE, JLE:
|
||||
switch x.Mnemonic {
|
||||
case JUMP:
|
||||
code = x64.Jump8(code, 0x00)
|
||||
case JE:
|
||||
code = x64.Jump8IfEqual(code, 0x00)
|
||||
case JNE:
|
||||
code = x64.Jump8IfNotEqual(code, 0x00)
|
||||
case JG:
|
||||
code = x64.Jump8IfGreater(code, 0x00)
|
||||
case JL:
|
||||
code = x64.Jump8IfLess(code, 0x00)
|
||||
case JGE:
|
||||
code = x64.Jump8IfGreaterOrEqual(code, 0x00)
|
||||
case JLE:
|
||||
code = x64.Jump8IfLessOrEqual(code, 0x00)
|
||||
}
|
||||
|
||||
size := 1
|
||||
label := x.Data.(*Label)
|
||||
nextInstructionAddress := Address(len(code))
|
||||
|
|
|
@ -34,10 +34,10 @@ func (a *Assembler) Register(mnemonic Mnemonic, register cpu.Register) {
|
|||
})
|
||||
}
|
||||
|
||||
// Label adds a label at the current position.
|
||||
func (a *Assembler) Label(name string) {
|
||||
// Label adds an instruction using a label.
|
||||
func (a *Assembler) Label(mnemonic Mnemonic, name string) {
|
||||
a.Instructions = append(a.Instructions, Instruction{
|
||||
Mnemonic: LABEL,
|
||||
Mnemonic: mnemonic,
|
||||
Data: &Label{
|
||||
Name: name,
|
||||
},
|
||||
|
|
|
@ -7,7 +7,14 @@ const (
|
|||
ADD
|
||||
CALL
|
||||
COMMENT
|
||||
COMPARE
|
||||
DIV
|
||||
JE
|
||||
JNE
|
||||
JG
|
||||
JGE
|
||||
JL
|
||||
JLE
|
||||
JUMP
|
||||
MUL
|
||||
LABEL
|
||||
|
@ -28,10 +35,24 @@ func (m Mnemonic) String() string {
|
|||
return "call"
|
||||
case COMMENT:
|
||||
return "comment"
|
||||
case COMPARE:
|
||||
return "compare"
|
||||
case DIV:
|
||||
return "div"
|
||||
case JUMP:
|
||||
return "jump"
|
||||
case JE:
|
||||
return "jump =="
|
||||
case JNE:
|
||||
return "jump !="
|
||||
case JL:
|
||||
return "jump <"
|
||||
case JG:
|
||||
return "jump >"
|
||||
case JLE:
|
||||
return "jump <="
|
||||
case JGE:
|
||||
return "jump >="
|
||||
case LABEL:
|
||||
return "label"
|
||||
case MOVE:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue