您可以通过重复减去机器代码来快速完成此操作.基本上你有一个程序,如:
set accumulator to N
subtract D
if carry flag is set then it is not divisible
if zero flag is set then it is divisible
otherwise repeat subtraction until one of the above occurs
Run Code Online (Sandbox Code Playgroud)
8位版本将是这样的:
DIVISIBLE_TEST:
LD B,10
LD A,100
DIVISIBLE_TEST_LOOP:
SUB B
JR C, $END_DIVISIBLE_TEST
JR Z, $END_DIVISIBLE_TEST
JR $DIVISIBLE_TEST_LOOP
END_DIVISIBLE_TEST:
LD B,A
LD C,0
RET
Run Code Online (Sandbox Code Playgroud)
现在,您可以使用USR从基本呼叫.USR返回的是BC寄存器对中的任何内容,因此您可能希望执行以下操作:
REM poke the memory addresses with the operands to load the registers
POKE X+1, D
POKE X+3, N
LET r = USR X
IF r = 0 THEN GOTO isdivisible
IF r <> 0 THEN GOTO isnotdivisible
Run Code Online (Sandbox Code Playgroud)
这是我写给Z80的介绍,应该可以帮助你解决这个问题.如果您不熟悉它们,这将解释标志.虽然它是Spectrum而不是ZX81,但是有更多链接可以从主站点获得良好的Z80内容.
16位版本将非常相似,但使用寄存器对操作.如果你需要超过16位,它会有点复杂.
如何加载它取决于你 - 但传统的方法是使用DATA语句和POKE.您可能更愿意让汇编程序为您找出机器代码!