LMC advanced
Advanced Challenge 1
Ask the user for a big number, then a small number. Using only a BRP, to loop round, keep subtracting the smaller number until you get past zero, then output the result.
>// Ask the user for a big number, then a small number. Using only a BRP to loop round, keep subtracting the smaller number until you get past zero, then output the result.
INP
STA 0
INP
STA 1
LDA 0
BRP 8
// how dare you, don't enter a negative number :(
OUT
HLT
SUB 1
BRP 8
OUT
// https://asciinema.org/a/s7Ol5SNffDrbBNmI8g2nO6r7P
View the playback [asciinema.org]
Advanced Challenge 2
To declare a constant you need to write it like this:
one DAT 1
(this will give the variable one
the value 1 and it will not change).
Using this, add to your previous program to count the number of times you can successfully subtract the smaller number.
>// To declare a constant you need to write it like this:
// one DAT 1 (this will give the variable one the value 1 and it will not change).
// Using this, add to your previous program to count the number of times you can successfully subtract the smaller number.
INP
STA 0
INP
STA 1
LDA 0
BRP 11
// how dare you, don't enter a negative number :(
OUT
LDA 9
OUT
HLT
DAT 1
SUB 1
STA 0
LDA 9
ADD 10
STA 9
LDA 0
BRP 11
OUT
LDA 9
SUB 10 // this is due to an off-by-one error
OUT
// https://asciinema.org/a/iK7S5ZcfNq3ly6okXMqBDfGxw