updated the lunar lander example
This commit is contained in:
+23
-24
@@ -12,7 +12,6 @@
|
||||
; 8888 is a perfect landing.
|
||||
; Created by Luxferre in 2025, released into public domain
|
||||
|
||||
set 1 0 50 ; set constant 1 to loc 50
|
||||
set 10 0 52 ; altitude threshold AND time period into loc 52
|
||||
set 16 2500 53 ; freefall speed delta into loc 53
|
||||
set 7480 0 54 ; capsule weight (in kg) into loc 54
|
||||
@@ -20,7 +19,7 @@ set 3 4483 55 ; fuel burn rate (3.4483) into loc 55
|
||||
set 2900 0 56 ; exhaust velocity (m/s) into loc 56
|
||||
set 1930 0 40 ; starting altitude (m) into loc 40
|
||||
set 100 0 57 ; store 100 into loc 57
|
||||
fma 0 57 40 ; multiply this altitude value by 100
|
||||
mul 57 40 ; multiply this altitude value by 100
|
||||
set 1609 0 41 ; starting speed (m/s) into loc 41
|
||||
set 7260 0 42 ; starting fuel (in kg) into loc 42
|
||||
set 4444 0 30 ; disaster code into loc 30
|
||||
@@ -34,44 +33,44 @@ set 4 4445 0 38 ; criterion for good landing into loc 38
|
||||
set 0 4500 0 39 ; criterion for perfect landing into loc 39
|
||||
:lp out 40 42 0 ; loop start; print altitude, speed and fuel
|
||||
set 0 0 2 ; set fuel loss in loc 2 to 0
|
||||
jmp 4 42 :cnt ; skip prompting for thrust if already out of fuel
|
||||
jle 42 :cnt ; skip prompting for thrust if already out of fuel
|
||||
inp 1 1 0 ; prompt for thrust into loc 1
|
||||
cpy 1 1 2 ; copy thrust into loc 2
|
||||
fma 0 55 2 ; multiply thrust by fuel burn rate to get fuel loss in loc 2
|
||||
cpy 1 42 3 ; copy fuel weight into loc 3
|
||||
:cnt fma 54 50 3 ; add capsule weight and fuel weight to get m0 in loc 3
|
||||
dva 1 2 ; copy thrust into loc 2
|
||||
mul 55 2 ; multiply thrust by fuel burn rate to get fuel loss in loc 2
|
||||
dva 42 3 ; copy fuel weight into loc 3
|
||||
:cnt fma 54 127 3 ; add capsule weight and fuel weight to get m0 in loc 3
|
||||
sub 3 2 4 ; subtract m0 and fuel loss value to get m1 in loc 4
|
||||
div 3 4 1 ; divide m0 by m1 and rewrite the result into loc 1
|
||||
nel 1 1 1 ; calculate natural logarithm of the previous result
|
||||
fma 0 56 1 ; multiply the result by the exhaust velocity to get thrust speed delta
|
||||
log 1 1 ; calculate natural logarithm of the previous result
|
||||
mul 56 1 ; multiply the result by the exhaust velocity to get thrust speed delta
|
||||
sub 41 1 41 ; subtract the thrust speed delta from the current speed
|
||||
fma 53 50 41 ; add the freefall speed delta to the current speed
|
||||
cpy 1 41 3 ; copy the speed value into loc 3
|
||||
fma 0 52 3 ; multiply speed by time period into loc 3
|
||||
fma 53 127 41 ; add the freefall speed delta to the current speed
|
||||
dva 41 3 ; copy the speed value into loc 3
|
||||
mul 52 3 ; multiply speed by time period into loc 3
|
||||
sub 40 3 40 ; decrease the altitude by the result of this operation
|
||||
sub 42 2 42 ; decrease the amount of fuel by fuel loss value still at loc 2
|
||||
jmp 1 42 :flc ; skip the next instruction if the amount of fuel is positive
|
||||
jgt 42 :flc ; skip the next instruction if the amount of fuel is positive
|
||||
set 0 0 42 ; just set the amount of fuel to zero if it's negative
|
||||
:flc jmp 1 40 :al ; do the same for altitude
|
||||
:flc jgt 40 :al ; do the same for altitude
|
||||
set 0 0 40 ; set it to zero if negative
|
||||
:al sub 40 52 1 ; subtract the threshold from the altitude
|
||||
jmp 1 1 :lp ; go to the loop start if the altitude is above the threshold
|
||||
jgt 1 :lp ; go to the loop start if the altitude is above the threshold
|
||||
out 40 42 0 ; print the final altitude/speed/fuel
|
||||
sub 41 39 1 ; subtract the perfect speed
|
||||
jmp 1 1 :good ; skip if > 0
|
||||
jgt 1 :good ; skip if > 0
|
||||
out 34 34 0 ; output the perfect score
|
||||
jmp 6 0 :end ; go to end
|
||||
juc :end ; go to end
|
||||
:good sub 41 38 1 ; subtract the good speed
|
||||
jmp 1 1 :dmg ; skip if > 0
|
||||
jgt 1 :dmg ; skip if > 0
|
||||
out 33 33 0 ; output the good score
|
||||
jmp 6 0 :end ; go to end
|
||||
juc :end ; go to end
|
||||
:dmg sub 41 37 1 ; subtract the damage speed
|
||||
jmp 1 1 :crsh ; skip if > 0
|
||||
jgt 1 :crsh ; skip if > 0
|
||||
out 32 32 0 ; output the damage score
|
||||
jmp 6 0 :end ; go to end
|
||||
juc :end ; go to end
|
||||
:crsh sub 41 36 1 ; subtract the crash speed
|
||||
jmp 1 1 :disa ; skip if > 0
|
||||
jgt 1 :disa ; skip if > 0
|
||||
out 31 31 0 ; output the crash score
|
||||
jmp 6 0 :end ; go to end
|
||||
juc :end ; go to end
|
||||
:disa out 30 30 0 ; output the disaster score
|
||||
:end nop 0 0 0 ; program end label
|
||||
:end nnn ; program end label
|
||||
|
||||
Reference in New Issue
Block a user