Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Found my first silicon bug

Found my first silicon bug

Scheduled Pinned Locked Moved The Lounge
hardwaredebugginghelp
21 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Mircea Neacsu

    As Griff was saying:

    Quote:

    Joy when I worked out what it was and reported it to the ops manager. Who just said "yeah, we know about that one..." and left me feeling very flat.

    I worked it out what it is and here is my result. Z80 processor has/had an instruction DJNZ that decrements register B and jumps if not zero. This is bread and butter of most small loops in Z80 assembly. It also has a set of "alternate" registers BC', DE' HL' but rather few instructions operate on those alternate registers. To compensate for this, Rabbit introduced an ALTD prefix that can be added to most instructions to make them operate on the alternate registers. Now what happens with the instruction ALTD DJNZ? Well, it takes the content of B register, decrements it and stores it in B' register making it a fairly useless instruction. Of course, this is not documented in the manual and you have to figure it out for yourself. Anyway, it left me feeling very flat :)

    Mircea

    OriginalGriffO Offline
    OriginalGriffO Offline
    OriginalGriff
    wrote on last edited by
    #12

    The alt registers (or "shadow" registers) I always kept for interrupts (or NMI when we used that) so we could work faster - memory access to stack the registers is a load slower than EXX which was only 4 T states, compared to a minimum of 11 (plus any memory wait states) for a PUSH. With a 4MHz processor, you shaved T states where you could! :-D

    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

    1 Reply Last reply
    0
    • M Mircea Neacsu

      As Griff was saying:

      Quote:

      Joy when I worked out what it was and reported it to the ops manager. Who just said "yeah, we know about that one..." and left me feeling very flat.

      I worked it out what it is and here is my result. Z80 processor has/had an instruction DJNZ that decrements register B and jumps if not zero. This is bread and butter of most small loops in Z80 assembly. It also has a set of "alternate" registers BC', DE' HL' but rather few instructions operate on those alternate registers. To compensate for this, Rabbit introduced an ALTD prefix that can be added to most instructions to make them operate on the alternate registers. Now what happens with the instruction ALTD DJNZ? Well, it takes the content of B register, decrements it and stores it in B' register making it a fairly useless instruction. Of course, this is not documented in the manual and you have to figure it out for yourself. Anyway, it left me feeling very flat :)

      Mircea

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #13

      Looks documented to me. The ALTD flag only changes the destination.

      Mircea Neacsu wrote:

      it takes the content of B register, decrements it and stores it in B register

      I believe what is actually happening here is that the ALTD instruction is setting the destination of the DJNZ operation to one of the "alternate" registers which leaves the B register unchanged. Best Wishes, -David Delaune

      M 1 Reply Last reply
      0
      • L Lost User

        Looks documented to me. The ALTD flag only changes the destination.

        Mircea Neacsu wrote:

        it takes the content of B register, decrements it and stores it in B register

        I believe what is actually happening here is that the ALTD instruction is setting the destination of the DJNZ operation to one of the "alternate" registers which leaves the B register unchanged. Best Wishes, -David Delaune

        M Offline
        M Offline
        Mircea Neacsu
        wrote on last edited by
        #14

        You are right; I should have paid more attention. However, it seems to me that it drastically reduces the usefulness of the instruction.

        Mircea

        L 1 Reply Last reply
        0
        • M Mircea Neacsu

          You are right; I should have paid more attention. However, it seems to me that it drastically reduces the usefulness of the instruction.

          Mircea

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #15

          Mircea Neacsu wrote:

          You are right; I should have paid more attention.

          Too bad you didn't find a cpu bug. :rose:

          Mircea Neacsu wrote:

          However, it seems to me that it drastically reduces the usefulness of the instruction.

          Of course, more registers are almost always better! :-D Best Wishes, -David Delaune

          M 1 Reply Last reply
          0
          • L Lost User

            Mircea Neacsu wrote:

            You are right; I should have paid more attention.

            Too bad you didn't find a cpu bug. :rose:

            Mircea Neacsu wrote:

            However, it seems to me that it drastically reduces the usefulness of the instruction.

            Of course, more registers are almost always better! :-D Best Wishes, -David Delaune

            M Offline
            M Offline
            Mircea Neacsu
            wrote on last edited by
            #16

            Quote:

            Too bad you didn't find a cpu bug.

            Well the chase was exiting :laugh:

            Mircea

            L U 2 Replies Last reply
            0
            • M Mircea Neacsu

              Quote:

              Too bad you didn't find a cpu bug.

              Well the chase was exiting :laugh:

              Mircea

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #17

              Mircea Neacsu wrote:

              chase was exiting

              Your chase might be exiting but with an altd djnz instruction your loops will never be exiting. :-\ However with this pedantic joke this thread has become much more exciting. ;P Best Wishes, -David Delaune

              1 Reply Last reply
              0
              • M Mircea Neacsu

                Quote:

                Most probably not. Test again and again ask yourself again and again is it really the processor and not your side.

                I did and I'm fairly sure this is not the case. Filed a bug report and we'll see what happens. I don't have any qualms admitting my errors so I promise I'll post the "denouement" :D

                Mircea

                G Offline
                G Offline
                GenJerDan
                wrote on last edited by
                #18

                Mircea Neacsu wrote:

                I don't have any qualms admitting my errors so I promise I'll post the "denouement"

                And if it turns out you were right, will we have to call you Mircea cel Mare?

                We won't sit down. We won't shut up. We won't go quietly away. YouTube, and My Mu[sic], Films and Windows Programs, etc. and FB

                M 1 Reply Last reply
                0
                • G GenJerDan

                  Mircea Neacsu wrote:

                  I don't have any qualms admitting my errors so I promise I'll post the "denouement"

                  And if it turns out you were right, will we have to call you Mircea cel Mare?

                  We won't sit down. We won't shut up. We won't go quietly away. YouTube, and My Mu[sic], Films and Windows Programs, etc. and FB

                  M Offline
                  M Offline
                  Mircea Neacsu
                  wrote on last edited by
                  #19

                  Quote:

                  And if it turns out you were right,

                  Unfortunately that's not the case. It was just my misreading of documentation as @Randor pointed out[^]. Anyway, as they say, the journey is more important than the destination and this one was a fun one :)

                  Mircea

                  1 Reply Last reply
                  0
                  • M Mircea Neacsu

                    Quote:

                    Too bad you didn't find a cpu bug.

                    Well the chase was exiting :laugh:

                    Mircea

                    U Offline
                    U Offline
                    User 12891772
                    wrote on last edited by
                    #20

                    @Mircea We have some of those boards integrated as part of industrial control systems, anything specific we need to worry about?

                    M 1 Reply Last reply
                    0
                    • U User 12891772

                      @Mircea We have some of those boards integrated as part of industrial control systems, anything specific we need to worry about?

                      M Offline
                      M Offline
                      Mircea Neacsu
                      wrote on last edited by
                      #21

                      No, I don't think so. The only possible damage is to my ego but I'm a big boy and I can take it :laugh: I was programming a particularly tight loop to read from an SPI device and thought I could use ALTD DJNZ instruction to shave some cycles and use the alternate B register. It turns out the ALTD prefix in this case is useless as I explained in a previous message. However, an instruction not doing what I expected can hardly be called a bug. No one has yet implemented the RPM (Read Programmer's Mind) instruction. :)

                      Mircea

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups