Z80 DAA指令 [英] Z80 DAA instruction

查看:157
本文介绍了Z80 DAA指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为这个看似次要的问题表示歉意,但我似乎找不到任何答案-我只是打算在我的Z80仿真器中实现DAA指令,并且在Zilog手册中注意到这是针对调整累加器以进行二进制编码的十进制算术的目的.它说该指令旨在在加法或减法指令之后立即运行.

Apologies for this seemingly minor question, but I can't seem to find the answer anywhere - I'm just coming up to implementing the DAA instruction in my Z80 emulator, and I noticed in the Zilog manual that it is for the purposes of adjusting the accumulator for binary coded decimal arithmetic. It says the instruction is intended to be run right after an addition or subtraction instruction.

我的问题是:

  • 如果在另一条指令后运行该怎么办?
  • 它如何知道之前的指令是什么?
  • 我意识到这里有N标志-但这肯定不能肯定地表明前一条指令是加法还是减法指令?
  • 不管之前的指令是什么,它是否只是根据DAA表中列出的条件修改了累加器?

推荐答案

不管之前的指令是什么,它是否只是根据DAA表中列出的条件修改了累加器?

Does it just modify the accumulator anyway, based on the conditions set out in the DAA table, regardless of the previous instruction?

是的.该文档仅告诉您DAA打算用于什么目的.也许您正在参考此链接中的表格:

Yes. The documentation is only telling you what DAA is intended to be used for. Perhaps you are referring to the table at this link:

--------------------------------------------------------------------------------
|           | C Flag  | HEX value in | H Flag | HEX value in | Number  | C flag|
| Operation | Before  | upper digit  | Before | lower digit  | added   | After |
|           | DAA     | (bit 7-4)    | DAA    | (bit 3-0)    | to byte | DAA   |
|------------------------------------------------------------------------------|
|           |    0    |     0-9      |   0    |     0-9      |   00    |   0   |
|   ADD     |    0    |     0-8      |   0    |     A-F      |   06    |   0   |
|           |    0    |     0-9      |   1    |     0-3      |   06    |   0   |
|   ADC     |    0    |     A-F      |   0    |     0-9      |   60    |   1   |
|           |    0    |     9-F      |   0    |     A-F      |   66    |   1   |
|   INC     |    0    |     A-F      |   1    |     0-3      |   66    |   1   |
|           |    1    |     0-2      |   0    |     0-9      |   60    |   1   |
|           |    1    |     0-2      |   0    |     A-F      |   66    |   1   |
|           |    1    |     0-3      |   1    |     0-3      |   66    |   1   |
|------------------------------------------------------------------------------|
|   SUB     |    0    |     0-9      |   0    |     0-9      |   00    |   0   |
|   SBC     |    0    |     0-8      |   1    |     6-F      |   FA    |   0   |
|   DEC     |    1    |     7-F      |   0    |     0-9      |   A0    |   1   |
|   NEG     |    1    |     6-F      |   1    |     6-F      |   9A    |   1   |
|------------------------------------------------------------------------------|

我必须说,我从来没有看过dafter指令规范.如果仔细检查表,您会发现指令的效果仅取决于CH标志以及累加器中的值-根本不取决于上一条指令.同样,它也不会泄露例如C=0H=1并且累加器中的低位数字为4或5的情况.因此,在这种情况下,您将必须执行NOP或生成错误消息或其他内容.

I must say, I've never seen a dafter instruction spec. If you examine the table carefully, you will see that the effect of the instruction depends only on the C and H flags and the value in the accumulator -- it doesn't depend on the previous instruction at all. Also, it doesn't divulge what happens if, for example, C=0, H=1, and the lower digit in the accumulator is 4 or 5. So you will have to execute a NOP in such cases, or generate an error message, or something.

这篇关于Z80 DAA指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆