开发者

Z80: How to add 16 and 8 bit registers?

开发者 https://www.devze.com 2022-12-19 18:54 出处:网络
How do you add a 16 and a 开发者_StackOverflow8 bit register with carry (for example, HL, and A)?I would like to point out that the checked response (by Carl Norum) is correct, but not the best answer

How do you add a 16 and a 开发者_StackOverflow8 bit register with carry (for example, HL, and A)?


I would like to point out that the checked response (by Carl Norum) is correct, but not the best answer. The following shows the speed of the two strategies with clock cycles. Using the right solution saves time, and won't destroy a second 16 bit register pair.

  4   ld c,a            4   add a,l
  7   ld b,0            4   ld l,a
  11  add hl,bc         4   adc a,h
                        4   sub l
                        4   ld h,a

However, the solution on the right does take an extra byte of code.


You can't do it directly. You need to copy A into a 16-bit register pair and then do the add:

LD  B, 0
LD  C, A
ADC HL, BC


From http://nemesis.lonestar.org/computers/tandy/software/apps/m4/qd/opcodes.html

Add Byte with Carry-In Instructions
8080 Mnemonic Z80 Mnemonic  Machine Code Operation
ADC  M        ADC A,(HL)    8E           A <- A + (HL) + Carry
0

精彩评论

暂无评论...
验证码 换一张
取 消