Author Topic: Some general Questions  (Read 10942 times)

0 Members and 1 Guest are viewing this topic.

Offline FloppusMaximus

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 290
  • Rating: +57/-5
    • View Profile
Re: Some general Questions
« Reply #15 on: November 01, 2010, 10:29:19 pm »
Yeah, that's a somewhat surprising behavior for 16-bit adds, which has tripped me up more than once (and heck, I've written a Z80 emulator.)  So yeah, a 16-bit 'sbc' (with carry flag clear) followed by an 'add' really is, in essence, a 16-bit compare.  (Notice that the add will carry if and only if the sbc did.)  8080 compatibility for... the win, in this case.

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Some general Questions
« Reply #16 on: November 01, 2010, 10:39:23 pm »
Straight from the zilog manual for add hl, <register>:

Quote
Condition Bits Affected:
S is not affected
Z is not affected
H is set if carry out of bit 11; reset otherwise
P/V is not affected
N is reset
C is set if carry from bit 15; reset otherwise

To be honest, I actually forgot that S and Z were ignored. I bet somewhere in one of my programs I did that wrong.

Wait, what!? :o Sean McLaughlin, you lied to me!
« Last Edit: November 01, 2010, 10:40:17 pm by Runer112 »

Offline FloppusMaximus

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 290
  • Rating: +57/-5
    • View Profile
Re: Some general Questions
« Reply #17 on: November 01, 2010, 10:42:00 pm »
Did he?  I doubt it, he's a pretty smart guy. :)  Note that this is only the 16-bit ADD instruction; the 8-bit ADD affects the flags as you would expect.

Offline Aichi

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 290
  • Rating: +76/-3
    • View Profile
    • Devrays
Re: Some general Questions
« Reply #18 on: November 02, 2010, 10:48:05 am »
6) I have some trouble with the Tasm Compiler (from the 28 days tutorial). I want to store the program data byte (CursY) into the L register, but Tasm outputs a strange issue on this line, which I cant explain me. Source and Screenshot attached.


Offline FloppusMaximus

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 290
  • Rating: +57/-5
    • View Profile
Re: Some general Questions
« Reply #19 on: November 02, 2010, 10:13:19 pm »
That code will not do what you want.  You can't load an 8-bit value from memory directly into a register, except for the A register.  TASM interprets "ld l, (foo)" as "ld l, foo"; i.e., a request to store the value "foo" in L, not to store the contents of memory location "foo" in L; the Z80 doesn't have an instruction to do the latter.  TASM is then complaining because you're trying to store a 16-bit value in an 8-bit register.

What you want to do is either "ld hl, (foo)" or "ld a, (foo) / ld l, a".  Obviously the former will destroy the contents of H, while the latter will destroy the contents of A.

Offline Aichi

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 290
  • Rating: +76/-3
    • View Profile
    • Devrays
Re: Some general Questions
« Reply #20 on: November 03, 2010, 01:37:48 am »
Thank you very much, Floppus!

Offline Aichi

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 290
  • Rating: +76/-3
    • View Profile
    • Devrays
Re: Some general Questions
« Reply #21 on: November 04, 2010, 04:15:27 pm »
7) I have to add the value of register a into register c.

Code: [Select]
   add c, aor
Code: [Select]
   ex bc, af
    add a, c
    ex bc, af
doesnt work, so I use this:
Code: [Select]
   ld b, a
Bloop:
    inc c
    djnz Bloop
    dec c

My question is if this is the most efficient way for the solution.
« Last Edit: November 04, 2010, 04:17:51 pm by Aichi »

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Some general Questions
« Reply #22 on: November 04, 2010, 04:23:11 pm »
Code: [Select]
add a, c
Ld c, a

Destroys A but i believe its a lot faster than incrementing C up to 255 times just for a single loop O.O

EDIT: Did the math and this performs about 200 times faster than your loop on average D:
« Last Edit: November 04, 2010, 04:28:09 pm by Builderboy »

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: Some general Questions
« Reply #23 on: November 04, 2010, 04:56:41 pm »
My question is if this is the most efficient way for the solution.

Definitely not :o

And seeing as you're destroying B anyway, you can use that to temporarily store A while you use Builderboy's code.




Offline gangsterveggies

  • LV2 Member (Next: 40)
  • **
  • Posts: 36
  • Rating: +2/-1
  • Asm rules
    • View Profile
Re: Some general Questions
« Reply #24 on: November 09, 2010, 02:44:53 pm »
Another thing... I know this isn't really related to the discussion but it matches the title...

I am a fresh beginner and there are some things I still don't know... what's the difference between "BCALL" and "B_CALL"?
I'm waiting for someone to do a calc Farmville. Maybe one day I'll do it!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Some general Questions
« Reply #25 on: November 09, 2010, 02:45:41 pm »
There are none. It's simply a different code formatting accross different ASM IDE/compilers.
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

Offline gangsterveggies

  • LV2 Member (Next: 40)
  • **
  • Posts: 36
  • Rating: +2/-1
  • Asm rules
    • View Profile
Re: Some general Questions
« Reply #26 on: November 09, 2010, 03:06:07 pm »
Oh... I had an idea why... again thanks.
I'm waiting for someone to do a calc Farmville. Maybe one day I'll do it!

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: Some general Questions
« Reply #27 on: November 09, 2010, 08:01:59 pm »
Yep, same with the underscore in _GetKey and all those other b_calls. Each assembler assembles differently (but tiDE is going to take any, I think).