Z80 汇编语言 - INC r 后的符号标志

发布于 2024-10-17 23:04:05 字数 97 浏览 4 评论 0原文

Z80 汇编语言的一件事让我困扰。符号标志是否总是代表A寄存器值的符号?我的意思是,当我运行“INC B”时,结果返回到 B,那么符号标志是否取自 A 或 B 寄存器的值?提前致谢

one thing with Z80 assembly language bothers me. Does sign flag always represent the sign of the value of the A register? I mean, when I run 'INC B', the result goes back to B, so is the sign flag taken from the value of the A or B register? Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

机场等船 2024-10-24 23:04:05

此页面:http://icarus.ticalc.org/articles/z80_faq.html 似乎指示符号标志代表任何计算的结果,而不仅仅是 A 寄存器上的计算结果。

This page: http://icarus.ticalc.org/articles/z80_faq.html seems to indicate that the sign flag represents the result of any calculation not just those on the A register.

寄人书 2024-10-24 23:04:05

Z80下所有寄存器(A、B、C、D、E、H、L)都是独立的,因此任何算术或二进制运算都会影响F寄存器中的标志。

检查 Z80 数据表第 160 页的 inc r 受影响的标志。

Under Z80 are all registers (A,B,C,D,E,H,L) independent, so any arithemtic or binary operation will affect to flags in F register.

Check Z80 datasheet page 160 for inc r affected flags.

守望孤独 2024-10-24 23:04:05

符号标志并不总是代表 A。溢出(包括 255)、按位运算(移位等)和逻辑运算符会影响所有标志。

然而,Zilog 对每个寄存器的设置不同,因此某些操作会影响特定寄存器的标志,而不影响另一个寄存器。常见的优化是“XOR A”,它设置符号标志并有效地将 A 与零进行比较。我很确定它只适用于 reg A。

前面提到的 Icarus 文档解释了这些标志,并且曾经有另一个更小的文本文档解释了这些标志。但我上次看到那是十多年前的事了,我不知道它会在哪里。

The sign flag doesn't always represent A. Overflow (inc on 255), bitwise operations (shift, etc), and logical operators affect all the flags.

However, Zilog set up each register differently, so some operations affect flags with a particular register and not another one. A common optimization is "XOR A", which sets the sign flag and effectively compares A to zero. I'm pretty sure it only works on reg A.

The aforementioned Icarus doc explains the flags and there used to be another even smaller text doc that explains the flags. But last time I saw that was 10+ years ago and i have no idea where it would be.

南巷近海 2024-10-24 23:04:05

Z80 中的标志始终指的是修改它们的最后一个操作。这种行为可能有用,也可能没那么有用。只是给你几个具体的例子:

ld l,0           ; L is non-zero, but loading does not affect flags,
                 ; so their state is undefined at this stage
xor a            ; this resets A to 0; affected flags are NC, Z
ld h,a           ; we still have NC, Z
inc hl           ; HL is now equal to 1, but inc/dec of register pairs does
                 ; not affect any flags at all
dec a            ; A is now 255 (i.e. -1). we have NZ (expectedly),
                 ; however flag C is still off (intuitively unexpectedly),
                 ; because DEC of individual registers does not affect state of flag C
add a,1          ; at the same time, addition modifies both Z and C,
                 ; so after this A=0 again and we have flags Z and C both on

一般来说,这意味着有时你可以构造更复杂的条件来跟踪标志 C 的状态,同时执行修改标志 Z 的其他操作而不修改标志 C。这也意味着你必须记住每个操作,它会修改哪些标志。

据我所知,包含所有这些信息的最佳在线表格位于 http://clrhome.org/table/

The flags in Z80 are always referring to the last operation that modified them. This behaviour could be useful or not so useful. Just to give you several specific examples:

ld l,0           ; L is non-zero, but loading does not affect flags,
                 ; so their state is undefined at this stage
xor a            ; this resets A to 0; affected flags are NC, Z
ld h,a           ; we still have NC, Z
inc hl           ; HL is now equal to 1, but inc/dec of register pairs does
                 ; not affect any flags at all
dec a            ; A is now 255 (i.e. -1). we have NZ (expectedly),
                 ; however flag C is still off (intuitively unexpectedly),
                 ; because DEC of individual registers does not affect state of flag C
add a,1          ; at the same time, addition modifies both Z and C,
                 ; so after this A=0 again and we have flags Z and C both on

Generally speaking, this means that sometimes you can construct more complex conditions that keep track of state of the flag C, while doing other operations that modify flag Z without modifying flag C. This also means that you must remember for each operation, which flags it modifies.

The best online table that I know of with all this information is located at http://clrhome.org/table/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文