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

0 Members and 1 Guest are viewing this topic.

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Another question..
« on: May 27, 2011, 02:00:51 pm »
how do you compare number bigger than 256?
i know cp compares number to accumulator, but it can only hold up to 256.. so how? ???

Ashbad

  • Guest
Re: Another question..
« Reply #1 on: May 27, 2011, 02:06:10 pm »
you can always do things such as subtracting DE from HL to compare 16 bit numbers and look at different flags.  Also, I suggest from now on, you rename resolved threads to something like "Assembly questions" rather than a whole new thread per small question ;)

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: Another question..
« Reply #2 on: May 27, 2011, 02:07:19 pm »
haha okay :D and thanks!

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 #3 on: May 27, 2011, 02:07:28 pm »
Load the value to HL (since that's two bytes), load the second value to either DE or BC, reset the carry flag, and use SBC to subtract the values. For example,

Code: (Z80 ASM) [Select]
    LD HL,256    ; Two-byte number
    LD DE,257    ; Another two-byte number
    OR A    ; Reset carry flag
    SBC HL,DE    ; Subtraction with carry
    JR C,Carried    ; This will get executed because HL-DE is less than zero
« Last Edit: May 27, 2011, 02:24:42 pm by Deep Thought »




Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: Another question..
« Reply #4 on: May 27, 2011, 02:21:35 pm »
thank you! now i get it! haha :D

SirCmpwn

  • Guest
Re: Another question..
« Reply #5 on: May 27, 2011, 02:22:52 pm »
Code: [Select]
CPDEBC:
    push de
    ex de, hl
    or a
    sbc hl, bc
    ex de, hl
    pop de
    ret
Preserves all registers, etc, and sets flags just like CP.

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: Another question..
« Reply #6 on: May 27, 2011, 02:24:45 pm »
oh yeah can you explain what's "or a" or "xor a" is? i dont know where to learn about them.

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 #7 on: May 27, 2011, 02:25:33 pm »
Sorry don't use XOR A. Not sure what I was thinking :P

OR A does the binary OR comparison of A to itself. All you have to know about it is that it resets the zero and carry flags (that's pretty much all it's used for) :)
« Last Edit: May 27, 2011, 02:26:35 pm by Deep Thought »




Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: Another question..
« Reply #8 on: May 27, 2011, 02:29:49 pm »
ah okay. haha :) so or only compares to accumulator? can you do like or hl?

SirCmpwn

  • Guest
Re: Another question..
« Reply #9 on: May 27, 2011, 02:34:58 pm »
oh yeah can you explain what's "or a" or "xor a" is? i dont know where to learn about them.
Those involve Bitwise Arithmetic.  It modifies numbers based on their binary values.
The following:
XOR B
Will apply XOR logic on A and B.  The logic is as follows, using registers A and B for examples:
Value of A: 11110101
Value of B: 10011011
AND
A AND B will preserve the ones in B and overwrite the zeros in A. (1 and 1 = 1, 0 and 0 = 0, 1 and 0 = 0)

    11110101 (A)
and 10011011 (B)
------------------
    10010001


OR
OR does the opposite: (1 or 0 = 1, 0 or 1 = 1, 0 or 0 = 0)
    11110101 (A)
or  10011011 (B)
------------------
    11111111


XOR
XOR toggles the bits in A that are 1 in B. (1 xor 0 = 1, 0 xor 1 = 1, 1 xor 1 = 0)
    11110101 (A)
xor 10011011 (B)
------------------
    01101110
« Last Edit: May 27, 2011, 02:54:16 pm by SirCmpwn »

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: Another question..
« Reply #10 on: May 27, 2011, 02:48:04 pm »
woahh! :D thats interesting. Thank you for that!   :thumbsup:
« Last Edit: May 27, 2011, 02:48:55 pm by TiAddict »

SirCmpwn

  • Guest
Re: Another question..
« Reply #11 on: May 27, 2011, 02:50:22 pm »
Sure thing.  Make sure you look back over it again, there were about 10 edits <_<

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: Another question..
« Reply #12 on: May 27, 2011, 02:52:13 pm »
hahahahha :) aiight! thank you for your time! :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 #13 on: May 27, 2011, 04:22:35 pm »
Since it hasn't been mentioned, (though it's been stepped around), here is calc84's CP HL, DE:
Code: [Select]
or a ;reset carry flag
sbc hl, de
add hl, de
This one is small enough that it doesn't need it's own call, so just put it inline like you would CP A. And just like SirCmpwn said, this messes with the flags in the exact same way that CP A does.
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 Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Another question..
« Reply #14 on: May 27, 2011, 04:27:17 pm »
And just like SirCmpwn said, this messes with the flags in the exact same way that CP A does.

It affects the n flag differently. ;)