Implemented if statements

This commit is contained in:
2024-07-07 12:30:57 +02:00
parent 6fc234c700
commit 91e300e49a
16 changed files with 280 additions and 14 deletions

View File

@ -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))