mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
IR: using EXT more
This commit is contained in:
parent
7ec4ba40ad
commit
513611c5a6
@ -348,15 +348,19 @@ internal class BuiltinFuncGen(private val codeGen: IRCodeGen, private val exprGe
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun funcMkword(call: PtBuiltinFunctionCall): ExpressionCodeResult {
|
private fun funcMkword(call: PtBuiltinFunctionCall): ExpressionCodeResult {
|
||||||
// TODO use ext instruction if msb is 0
|
|
||||||
val result = mutableListOf<IRCodeChunkBase>()
|
val result = mutableListOf<IRCodeChunkBase>()
|
||||||
val msbTr = exprGen.translateExpression(call.args[0])
|
|
||||||
addToResult(result, msbTr, msbTr.resultReg, -1)
|
|
||||||
val lsbTr = exprGen.translateExpression(call.args[1])
|
|
||||||
addToResult(result, lsbTr, lsbTr.resultReg, -1)
|
|
||||||
val resultReg = codeGen.registers.nextFree()
|
val resultReg = codeGen.registers.nextFree()
|
||||||
result += IRCodeChunk(null, null).also {
|
if((call.args[0] as? PtNumber)?.number == 0.0) {
|
||||||
it += IRInstruction(Opcode.CONCAT, IRDataType.BYTE, reg1=resultReg, reg2 = msbTr.resultReg, reg3 = lsbTr.resultReg)
|
// msb is 0, use EXT
|
||||||
|
val lsbTr = exprGen.translateExpression(call.args[1])
|
||||||
|
addToResult(result, lsbTr, lsbTr.resultReg, -1)
|
||||||
|
addInstr(result, IRInstruction(Opcode.EXT, IRDataType.BYTE, reg1=resultReg, reg2 = lsbTr.resultReg), null)
|
||||||
|
} else {
|
||||||
|
val msbTr = exprGen.translateExpression(call.args[0])
|
||||||
|
addToResult(result, msbTr, msbTr.resultReg, -1)
|
||||||
|
val lsbTr = exprGen.translateExpression(call.args[1])
|
||||||
|
addToResult(result, lsbTr, lsbTr.resultReg, -1)
|
||||||
|
addInstr(result, IRInstruction(Opcode.CONCAT, IRDataType.BYTE, reg1=resultReg, reg2 = msbTr.resultReg, reg3 = lsbTr.resultReg), null)
|
||||||
}
|
}
|
||||||
return ExpressionCodeResult(result, IRDataType.WORD, resultReg, -1)
|
return ExpressionCodeResult(result, IRDataType.WORD, resultReg, -1)
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,10 @@
|
|||||||
|
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
uword sprite_reg
|
ubyte lower = 123
|
||||||
cx16.r0 = sprite_reg+1
|
ubyte upper = 0
|
||||||
cx16.vpoke(1, sprite_reg+1, 42)
|
uword ww = mkword(upper, lower)
|
||||||
|
|
||||||
|
txt.print_uwhex(ww, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user