13 votes

Guide to Z80 ASM basics

Tags: z80, assembly

I've been thinking about messing around with Z80 ASM for a while with the end goal of doing interesting things with one of my old TI calculators. Finally got around to doing some googling, found this guide to the basics, and thought I'd share it for anyone else who might like to read it.

9 comments

  1. [3]
    Emerald_Knight
    Link
    Assembly was an absolute nightmare for me. I had a required computer architecture course during my CS studies. Among the many topics like memory locality, we also covered assembly, which...

    Assembly was an absolute nightmare for me.

    I had a required computer architecture course during my CS studies. Among the many topics like memory locality, we also covered assembly, which completely threw me off. I also had a hard time paying attention during the lectures, so I was completely lost on that entire subject.

    Well, near the end of that section, the entire class was assigned the project of writing a Fibonacci algorithm in y86. I couldn't afford not to do the assignment, so I dive right in and try to get things working. I figured that at the very least, I could get partial credit for something that vaguely resembled an attempt.

    ...And I ended up spending hours upon hours failing to get things to work. I kept studying up on the instruction set and everything, looking at examples online to figure out how it all worked, and it just wouldn't give me the results I expected. Not even in the ballpark. I wrote and rewrote that program several times over an all-night stretch to no avail.

    Well, the next morning I ask a classmate to take a look and help me figure out what the hell was going on. Turned out the stack size was too small. After bumping it up, my program worked. Flawlessly. In the end, after those long, painstaking hours of bewilderment, I somehow ended up understanding assembly after all.

    Kind of went on a tangent, but any time the subject of assembly comes up, that entire experience comes straight to mind. I don't know how Roller Coaster Tycoon ended up being written 99% in assembly without its dev, Chris Sawyer, completely losing his mind.

    4 votes
    1. [2]
      arghdos
      Link Parent
      I wrote a binary tree in MIPS for a class once. The only limitation was it couldn't handle negative numbers as a key. It took me days to debug and get fully running, what a miserable experience!

      I wrote a binary tree in MIPS for a class once. The only limitation was it couldn't handle negative numbers as a key.

      It took me days to debug and get fully running, what a miserable experience!

      1 vote
      1. Emerald_Knight
        Link Parent
        A binary tree in MIPS sounds like a nightmare I'm not willing to deal with. It would definitely be doable, but there would be so much micromanaging that I'd lose my mind. I don't envy you one bit...

        A binary tree in MIPS sounds like a nightmare I'm not willing to deal with. It would definitely be doable, but there would be so much micromanaging that I'd lose my mind. I don't envy you one bit for having to go through that.

        1 vote
  2. [2]
    pseudolobster
    Link
    I've got to put a shout-out here to the book that first turned me on to ASM back in the day: Peter Norton's Assembly Language Book for the IBM PC. He explains in detail how to start out in...

    I've got to put a shout-out here to the book that first turned me on to ASM back in the day: Peter Norton's Assembly Language Book for the IBM PC. He explains in detail how to start out in assembly and shows step-by-step how to build a high-level program (a GUI-based hex editor) using it.

    The book teaches you 8088 with a lot of DOS-specific stuff involved but the lessons translate directly to the 8086 and more or less directly the Z80 series and others. The book is 30 years old at this point but I'd still recommend it since you're learning from one of the early masters and the book honestly explains things really well, even if you have no programming experience.

    2 votes
    1. sqew
      Link Parent
      Thanks for the lead on that! I'll definitely see if I can find the book sometime soon.

      Thanks for the lead on that! I'll definitely see if I can find the book sometime soon.

      1 vote
  3. [4]
    drg
    (edited )
    Link
    There is also the How to program the Z80. It is a nice mix of the basics of the hardware and of the Z80 ASM in a very readable form. It is one of my favorite Z80 books.

    There is also the How to program the Z80.

    It is a nice mix of the basics of the hardware and of the Z80 ASM in a very readable form. It is one of my favorite Z80 books.

    1 vote
    1. [2]
      Emerald_Knight
      Link Parent
      Just a heads up, link syntax on ~ isn't the same as on reddit. You'll want to use a simple HTML style anchor tag, e.g. <a href="http://www.z80.info/zip/zaks_book.pdf">How to program the Z80</a>.

      Just a heads up, link syntax on ~ isn't the same as on reddit. You'll want to use a simple HTML style anchor tag, e.g. <a href="http://www.z80.info/zip/zaks_book.pdf">How to program the Z80</a>.

      1 vote
      1. drg
        Link Parent
        Oops, sorry and thanks for the heads up!

        Oops, sorry and thanks for the heads up!

        1 vote
    2. sqew
      Link Parent
      Oh cool! Thank you, seems like another good resource to add to my list of Z80 books/guides!

      Oh cool! Thank you, seems like another good resource to add to my list of Z80 books/guides!