1

我尝试为 z80 程序集编写冒泡排序,但我发现我需要使用替代寄存器。但是推荐的语法(B')不起作用并引发错误。我怎样才能使用这些寄存器?

4

1 回答 1

6

没有直接使用影子寄存器的说明。
相反,有一条指令EXX可以将普通寄存器与影子寄存器交换。

让自己陷入黑暗面
如果您计划在中断处理程序之外使用影子寄存器1,您还必须在使用影子寄存器期间禁用中断

例子:

di           ;disable interrupts
exx          ;exchange registers BC,DE,HL with BC',DE',and HL'
ld b,8       ;do stuff with the shadow registers
....
exx          ;put the normal registers in charge
ei           ;re-enable interrupts

1 )仅当您的系统在中断处理程序中使用影子注册时才适用。

警告
不要在禁用中断的情况下进行冗长的计算,否则您的系统将无法对中断处理程序处理的外部输入做出反应。

还有一个用于 AF 的影子寄存器:AF'。
您可以这样访问:

ex af,af'    ;exchange af with its shadow register.

请注意,即使ex不影响标志本身,ex af,af'也会将标志寄存器与其影子交换。

欲了解更多信息,请参阅:http: //z80-heaven.wikidot.com/instructions-set

请注意,冒泡排序作为一种算法很糟糕,应该被禁止。
请改为 执行插入排序。

使用堆栈 Luke
如果你做冗长的处理,那么你不能使用影子寄存器,而必须使用堆栈而不是使用pushand pop

ld b,8              ;normal processing
push bc              ;save bc for later
ld b,9              ;extended processing
... do stuff with bc
pop bc               ;throw away the extended bc and restore the old bc.

…不。还有另一种。
如果堆栈没有为您切割它,您将不得不使用将值存储在内存中ld

ld b,8               ;do stuff with bc
ld (1000),bc         ;store bc for later
ld b,9               ;do other stuff
.....
ld (1002),bc         ;store the extended bc
ld bc,(1000)         ;restore the saved bc
....                 ;continue processing.

直接寻址内存的好处是您不必丢弃值。缺点是它的运行速度比堆栈慢一点。

于 2017-03-05T11:14:07.593 回答