Author Topic: Another question..  (Read 8178 times)

0 Members and 1 Guest are viewing this topic.

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: Another question..
« Reply #15 on: May 27, 2011, 04:40:44 pm »
umm sorry but what is "sbc"?

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Another question..
« Reply #16 on: May 27, 2011, 04:46:19 pm »
SBC is SuBtract with Carry. It's like SUB, but it also subtracts one if the carry flag is set. It's the only way to do 16-bit subtraction/comparison since SUB can only operate on A.
« Last Edit: May 27, 2011, 04:46:22 pm by Deep Thought »




Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: Another question..
« Reply #17 on: May 27, 2011, 04:47:36 pm »
oh i see. thanks Deep Thought! :D

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Another question..
« Reply #18 on: May 27, 2011, 04:50:34 pm »
Subtract with carry. It subtracts DE and the carry flag.

SBC is usually used when you need to do subtraction with 4 bytes and such.
Code: [Select]
;we will subtract big num 1 from big num 2

ld hl, (bigNum2) ;hl = $0201
ld de, (bigNum1) ;DE = $0605
or a ;this time we don't want the carry flag
sbc hl, de
ld (result), hl ;DE was bigger than HL, so the carry flag is set

ld hl, (bigNum2+2)
ld de, (bigNum1+2)
sbc hl, de ;since the last operation carried, (remember 2nd grade math)
ld (result+2), hl ;we had to subtract an extra 1 from this result

bigNum1:
.db 5, 6, 2, 3
bigNum2:
.db 1, 2, 8, 9
result:
.db 0, 0, 0, 0

This is what SBC is used for. But, we are forced to use it because SUB HL, DE doesn't exist. :P

I noticed that I have been ninja'd, but I don't care.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: Another question..
« Reply #19 on: May 27, 2011, 04:58:25 pm »
hahah thanks you for that! xD