mirror of
https://github.com/irmen/prog8.git
synced 2024-11-25 19:31:36 +00:00
fixed lsb() to uword problem
This commit is contained in:
parent
c1aa5d4e47
commit
450eaf7c4a
@ -1160,9 +1160,27 @@ internal class BuiltinFunctionsAsmGen(private val program: PtProgram,
|
||||
// and will not generate another cmp when lsb() is directly used inside a comparison expression.
|
||||
}
|
||||
RegisterOrPair.Y -> {
|
||||
asmgen.out(" pha")
|
||||
asmgen.assignExpressionToRegister(fcall.args.single(), RegisterOrPair.AY)
|
||||
asmgen.out(" tay | pla | cpy #0")
|
||||
asmgen.out(" tay | cpy #0")
|
||||
}
|
||||
RegisterOrPair.AY -> {
|
||||
asmgen.assignExpressionToRegister(fcall.args.single(), RegisterOrPair.AY)
|
||||
asmgen.out(" ldy #0 | cmp #0")
|
||||
}
|
||||
RegisterOrPair.AX -> {
|
||||
asmgen.assignExpressionToRegister(fcall.args.single(), RegisterOrPair.AX)
|
||||
asmgen.out(" ldx #0 | cmp #0")
|
||||
}
|
||||
RegisterOrPair.XY -> {
|
||||
asmgen.assignExpressionToRegister(fcall.args.single(), RegisterOrPair.XY)
|
||||
asmgen.out(" ldy #0 | cpx #0")
|
||||
}
|
||||
in Cx16VirtualRegisters -> {
|
||||
asmgen.assignExpressionToRegister(fcall.args.single(), resultRegister)
|
||||
val zero = PtNumber(DataType.UBYTE, 0.0, Position.DUMMY)
|
||||
zero.parent=fcall
|
||||
assignAsmGen.assignExpressionToVariable(zero, "cx16.${resultRegister.toString().lowercase()}H", DataType.UBYTE)
|
||||
asmgen.out(" lda cx16.r0L")
|
||||
}
|
||||
else -> throw AssemblyError("invalid reg")
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package prog8tests.codegencpu6502
|
||||
|
||||
import io.kotest.assertions.throwables.shouldNotThrowAny
|
||||
import io.kotest.assertions.withClue
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual
|
||||
import io.kotest.matchers.shouldBe
|
||||
import prog8.code.SymbolTableMaker
|
||||
import prog8.code.ast.*
|
||||
@ -107,9 +109,19 @@ class TestCodegen: FunSpec({
|
||||
test("64tass assembler available? - if this fails you need to install 64tass in the path") {
|
||||
val command = mutableListOf("64tass", "--version")
|
||||
shouldNotThrowAny {
|
||||
val proc = ProcessBuilder(command).inheritIO().start()
|
||||
val proc = ProcessBuilder(command).start()
|
||||
val output = String(proc.inputStream.readBytes())
|
||||
val result = proc.waitFor()
|
||||
result.shouldBe(0)
|
||||
val (_, version) = output.split('V')
|
||||
val (major, minor, _) = version.split('.')
|
||||
val majorNum = major.toInt()
|
||||
val minorNum = minor.toInt()
|
||||
withClue("64tass version should be 1.58 or newer") {
|
||||
majorNum shouldBeGreaterThanOrEqual 1
|
||||
if (majorNum == 1)
|
||||
minorNum shouldBeGreaterThanOrEqual 58
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -5,27 +5,37 @@ main
|
||||
{
|
||||
sub start()
|
||||
{
|
||||
ubyte res
|
||||
ubyte val=3
|
||||
when val*10 {
|
||||
1 -> res=1
|
||||
10 -> res=10
|
||||
20 -> res=20
|
||||
30 -> res=30
|
||||
40 -> res=40
|
||||
else -> res=0
|
||||
}
|
||||
uword zc = 54321
|
||||
ubyte zb = 123
|
||||
ubyte shift = 2
|
||||
|
||||
txt.print_ub(res) ; 30
|
||||
; txt.print_uw(zc<<shift)
|
||||
; txt.nl()
|
||||
; txt.print_uw(zc>>shift)
|
||||
; txt.nl()
|
||||
; txt.print_ub(zb<<shift)
|
||||
; txt.nl()
|
||||
; txt.print_ub(zb>>shift)
|
||||
; txt.nl()
|
||||
;
|
||||
; word szc = -12345
|
||||
; byte szb = -123
|
||||
; txt.print_w(szc<<shift)
|
||||
; txt.nl()
|
||||
; txt.print_w(szc>>shift)
|
||||
; txt.nl()
|
||||
; txt.print_b(szb<<shift)
|
||||
; txt.nl()
|
||||
; txt.print_b(szb>>shift)
|
||||
; txt.nl()
|
||||
;
|
||||
txt.print_uw(~zc as ubyte)
|
||||
txt.spc()
|
||||
txt.print_uw(~zb as uword)
|
||||
txt.nl()
|
||||
|
||||
when val {
|
||||
5,7,9,1,3 -> res=100
|
||||
2,4,6,8 -> res=200
|
||||
else -> res=0
|
||||
}
|
||||
|
||||
txt.print_ub(res) ; 100
|
||||
; 102 instructions, 31 registers, 122 steps
|
||||
; cx16.r1L = (zc<<shift) as ubyte
|
||||
; txt.print_ub(cx16.r1L)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user