diff --git a/compiler/res/prog8lib/floats_functions.p8 b/compiler/res/prog8lib/floats_functions.p8 index 3d281d8c5..3d1db59a8 100644 --- a/compiler/res/prog8lib/floats_functions.p8 +++ b/compiler/res/prog8lib/floats_functions.p8 @@ -215,4 +215,17 @@ sub clampf(float value, float minimum, float maximum) -> float { return minimum } +inline asmsub push(float value @FAC1) { + %asm {{ + jsr floats.pushFAC1 + }} +} + +inline asmsub pop() -> float @FAC1 { + %asm {{ + clc + jsr floats.popFAC + }} +} + } diff --git a/compiler/res/prog8lib/virtual/floats.p8 b/compiler/res/prog8lib/virtual/floats.p8 index 8e78bef79..5ac120312 100644 --- a/compiler/res/prog8lib/virtual/floats.p8 +++ b/compiler/res/prog8lib/virtual/floats.p8 @@ -173,4 +173,19 @@ sub normalize(float value) -> float { return value } +sub push(float value) { + %ir {{ + loadm.f fr65535,floats.push.value + push.f fr65535 + return + }} +} + +sub pop() -> float { + %ir {{ + pop.f fr65535 + returnr.f fr65535 + }} +} + } diff --git a/examples/test.p8 b/examples/test.p8 index 2332f5fe4..00c33aa06 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,17 +1,17 @@ %import textio -;;%import floats +%import floats %zeropage basicsafe main { sub start() { sys.push(11) sys.pushw(2222) - ;;floats.pushf(floats.π) + floats.push(floats.π) cx16.r2++ - ;;float pi = floats.popf() - ;;floats.print_f(pi) - ;;txt.nl() + float pi = floats.pop() + floats.print_f(pi) + txt.nl() cx16.r1 = sys.popw() cx16.r0L = sys.pop() diff --git a/virtualmachine/src/prog8/vm/VirtualMachine.kt b/virtualmachine/src/prog8/vm/VirtualMachine.kt index dd18029db..7c838ad75 100644 --- a/virtualmachine/src/prog8/vm/VirtualMachine.kt +++ b/virtualmachine/src/prog8/vm/VirtualMachine.kt @@ -2406,10 +2406,10 @@ internal fun Stack.popf(): Double { val bits = b7 + (1L shl 8)*b6 + (1L shl 16)*b5 + - (1L shl 24)*b4 - (1L shl 32)*b3 - (1L shl 40)*b2 - (1L shl 48)*b1 + (1L shl 24)*b4 + + (1L shl 32)*b3 + + (1L shl 40)*b2 + + (1L shl 48)*b1 + (1L shl 56)*b0 return Double.fromBits(bits) }