Improved branch compilation
This commit is contained in:
parent
871749101e
commit
13161f5021
9 changed files with 160 additions and 113 deletions
|
@ -57,7 +57,12 @@ func (a Assembler) Finalize() ([]byte, []byte) {
|
|||
Position: Address(len(code) - size),
|
||||
Size: uint8(size),
|
||||
Resolve: func() Address {
|
||||
destination := labels[label.Name]
|
||||
destination, exists := labels[label.Name]
|
||||
|
||||
if !exists {
|
||||
panic("unknown call label")
|
||||
}
|
||||
|
||||
distance := destination - nextInstructionAddress
|
||||
return Address(distance)
|
||||
},
|
||||
|
@ -100,7 +105,12 @@ func (a Assembler) Finalize() ([]byte, []byte) {
|
|||
Position: Address(len(code) - size),
|
||||
Size: uint8(size),
|
||||
Resolve: func() Address {
|
||||
destination := labels[label.Name]
|
||||
destination, exists := labels[label.Name]
|
||||
|
||||
if !exists {
|
||||
panic("unknown jump label")
|
||||
}
|
||||
|
||||
distance := destination - nextInstructionAddress
|
||||
return Address(distance)
|
||||
},
|
||||
|
|
|
@ -42,17 +42,17 @@ func (m Mnemonic) String() string {
|
|||
case JUMP:
|
||||
return "jump"
|
||||
case JE:
|
||||
return "jump =="
|
||||
return "jump if =="
|
||||
case JNE:
|
||||
return "jump !="
|
||||
return "jump if !="
|
||||
case JL:
|
||||
return "jump <"
|
||||
return "jump if <"
|
||||
case JG:
|
||||
return "jump >"
|
||||
return "jump if >"
|
||||
case JLE:
|
||||
return "jump <="
|
||||
return "jump if <="
|
||||
case JGE:
|
||||
return "jump >="
|
||||
return "jump if >="
|
||||
case LABEL:
|
||||
return "label"
|
||||
case MOVE:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue