-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a general conditional jump instruction (#44)
* Adds pseudo instructions for all comparisons * Updates example programs * Updates bf compiler * Updates README
- Loading branch information
Frank Stokes
committed
Aug 3, 2017
1 parent
8598714
commit 935290b
Showing
19 changed files
with
163 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ factorial: | |
pop A | ||
ldv B, 3 | ||
ldv D, done: | ||
jlt B, D | ||
JLT A, B, D | ||
|
||
psh a | ||
psh b | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,6 @@ main: | |
|
||
loop: | ||
cal D | ||
jne B, C | ||
jne A, B, C | ||
|
||
hlt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 5 additions & 41 deletions
46
src/assembler/preprocessor/stages/pseudo-instructions/expanders/conditional/JEQ.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,7 @@ | ||
const { | ||
getInstructionArguments, | ||
uniqueLabel, | ||
getUsableRegister | ||
} = require('../../../../utils'); | ||
const { getInstructionArguments } = require('../../../../utils'); | ||
const { JUMP } = require('../../../../../../constants'); | ||
|
||
module.exports = (instruction) => { | ||
const [source, addressRegister] = getInstructionArguments(instruction); | ||
const mutableRegister = getUsableRegister(source, addressRegister); | ||
|
||
const firstCheck = uniqueLabel(); | ||
const equal = uniqueLabel(); | ||
const notEqual = uniqueLabel(); | ||
|
||
return [ | ||
`PSH ${mutableRegister}`, // Push mr [mr] | ||
|
||
`PSH ${addressRegister}`, // Push ar [ar, mr] | ||
`LDV16 ${addressRegister}, ${firstCheck}`, | ||
`LDV16 ${mutableRegister}, ${notEqual}`, | ||
|
||
`JGE ${source}, ${addressRegister}`, | ||
`JMR ${mutableRegister}`, | ||
|
||
`${firstCheck}`, | ||
`LDV16 ${addressRegister}, ${equal}`, | ||
`SWP A, ${source}`, | ||
`JGE ${source}, ${addressRegister}`, | ||
|
||
`SWP A, ${source}`, | ||
`JMR ${mutableRegister}`, | ||
|
||
`${equal}`, | ||
`SWP A, ${source}`, | ||
`POP ${addressRegister}`, // Pop ar [mr] | ||
`POP ${mutableRegister}`, // Pop mr [] | ||
`JMR ${addressRegister}`, | ||
|
||
`${notEqual}`, | ||
`POP ${addressRegister}`, // Pop ar [mr] | ||
`POP ${mutableRegister}` // Pop mr [] | ||
]; | ||
} | ||
const [r1, r2, addressRegister] = getInstructionArguments(instruction); | ||
return [`JCP ${r1}, ${r2}, ${addressRegister}, ${JUMP.EQ}`]; | ||
}; |
27 changes: 5 additions & 22 deletions
27
src/assembler/preprocessor/stages/pseudo-instructions/expanders/conditional/JGE.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,7 @@ | ||
const { | ||
getInstructionArguments, | ||
uniqueLabel, | ||
getUsableRegister | ||
} = require('../../../../utils'); | ||
|
||
const { getInstructionArguments } = require('../../../../utils'); | ||
const { JUMP } = require('../../../../../../constants'); | ||
|
||
module.exports = (instruction) => { | ||
const [source, addressRegister] = getInstructionArguments(instruction); | ||
const lessThan = uniqueLabel(); | ||
const mutableRegister = getUsableRegister(source, addressRegister); | ||
|
||
return [ | ||
`PSH ${mutableRegister}`, | ||
`LDV16 ${mutableRegister}, ${lessThan}`, | ||
|
||
`JLT ${source}, ${mutableRegister}`, | ||
`POP ${mutableRegister}`, | ||
`JMR ${addressRegister}`, | ||
|
||
`${lessThan}`, | ||
`POP ${mutableRegister}` | ||
]; | ||
} | ||
const [r1, r2, addressRegister] = getInstructionArguments(instruction); | ||
return [`JCP ${r1}, ${r2}, ${addressRegister}, ${JUMP.GTE}`]; | ||
}; |
7 changes: 7 additions & 0 deletions
7
src/assembler/preprocessor/stages/pseudo-instructions/expanders/conditional/JGT.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { getInstructionArguments } = require('../../../../utils'); | ||
const { JUMP } = require('../../../../../../constants'); | ||
|
||
module.exports = (instruction) => { | ||
const [r1, r2, addressRegister] = getInstructionArguments(instruction); | ||
return [`JCP ${r1}, ${r2}, ${addressRegister}, ${JUMP.GT}`]; | ||
}; |
7 changes: 7 additions & 0 deletions
7
src/assembler/preprocessor/stages/pseudo-instructions/expanders/conditional/JLE.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { getInstructionArguments } = require('../../../../utils'); | ||
const { JUMP } = require('../../../../../../constants'); | ||
|
||
module.exports = (instruction) => { | ||
const [r1, r2, addressRegister] = getInstructionArguments(instruction); | ||
return [`JCP ${r1}, ${r2}, ${addressRegister}, ${JUMP.JLE}`]; | ||
}; |
7 changes: 7 additions & 0 deletions
7
src/assembler/preprocessor/stages/pseudo-instructions/expanders/conditional/JLT.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { getInstructionArguments } = require('../../../../utils'); | ||
const { JUMP } = require('../../../../../../constants'); | ||
|
||
module.exports = (instruction) => { | ||
const [r1, r2, addressRegister] = getInstructionArguments(instruction); | ||
return [`JCP ${r1}, ${r2}, ${addressRegister}, ${JUMP.LT}`]; | ||
}; |
26 changes: 5 additions & 21 deletions
26
src/assembler/preprocessor/stages/pseudo-instructions/expanders/conditional/JNE.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,7 @@ | ||
const { | ||
getInstructionArguments, | ||
uniqueLabel, | ||
getUsableRegister | ||
} = require('../../../../utils'); | ||
const { getInstructionArguments } = require('../../../../utils'); | ||
const { JUMP } = require('../../../../../../constants'); | ||
|
||
module.exports = (instruction) => { | ||
const [source, addressRegister] = getInstructionArguments(instruction); | ||
const equal = uniqueLabel(); | ||
const mutableRegister = getUsableRegister(source, addressRegister); | ||
|
||
return [ | ||
`PSH ${mutableRegister}`, | ||
`LDV16 ${mutableRegister}, ${equal}`, | ||
|
||
`JEQ ${source}, ${mutableRegister}`, | ||
`POP ${mutableRegister}`, | ||
`JMR ${addressRegister}`, | ||
|
||
`${equal}`, | ||
`POP ${mutableRegister}` | ||
]; | ||
} | ||
const [r1, r2, addressRegister] = getInstructionArguments(instruction); | ||
return [`JCP ${r1}, ${r2}, ${addressRegister}, ${JUMP.NEQ}`]; | ||
}; |
7 changes: 7 additions & 0 deletions
7
src/assembler/preprocessor/stages/pseudo-instructions/expanders/conditional/JNZ.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { getInstructionArguments } = require('../../../../utils'); | ||
const { JUMP } = require('../../../../../../constants'); | ||
|
||
module.exports = (instruction) => { | ||
const [r1, r2, addressRegister] = getInstructionArguments(instruction); | ||
return [`JCP ${r1}, ${r2}, ${addressRegister}, ${JUMP.NZE}`]; | ||
}; |
7 changes: 7 additions & 0 deletions
7
src/assembler/preprocessor/stages/pseudo-instructions/expanders/conditional/JZE.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { getInstructionArguments } = require('../../../../utils'); | ||
const { JUMP } = require('../../../../../../constants'); | ||
|
||
module.exports = (instruction) => { | ||
const [r1, r2, addressRegister] = getInstructionArguments(instruction); | ||
return [`JCP ${r1}, ${r2}, ${addressRegister}, ${JUMP.ZER}`]; | ||
}; |
14 changes: 12 additions & 2 deletions
14
src/assembler/preprocessor/stages/pseudo-instructions/expanders/conditional/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
const JEQ = require('./JEQ'); | ||
const JGE = require('./JGE'); | ||
const JNE = require('./JNE'); | ||
const JLT = require('./JLT'); | ||
const JGT = require('./JGT'); | ||
const JLE = require('./JLE'); | ||
const JGE = require('./JGE'); | ||
const JZE = require('./JZE'); | ||
const JNZ = require('./JNZ'); | ||
|
||
module.exports = { | ||
JEQ, | ||
JNE, | ||
JLT, | ||
JGT, | ||
JLE, | ||
JGE, | ||
JNE | ||
JZE, | ||
JNZ | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.