RosettaCodeData/Task/Even-or-odd/Little-Man-Computer/even-or-odd-1.lmc
2023-07-01 13:44:08 -04:00

13 lines
525 B
Text

// Input number; output its residue mod 2
INP // read input into acc
BRZ write // input = 0 is special case
loop SUB k2 // keep subtracting 2 from acc
BRZ write // if acc = 0, input is even
BRP loop // if acc > 0, loop back
// (BRP branches if acc >= 0, but we've dealt with acc = 0)
LDA k1 // if acc < 0, input is odd
write OUT // output 0 or 1
HLT // halt
k1 DAT 1 // constant 1
k2 DAT 2 // constant 2
// end