Skip to main content

Emulator Deep Dive - The Instruction Set: Part 4

This is the fourth part in this series, and will cover flow control instructions.

You can find the first post here, the second here, and the third here.

Prerequisites

None of the flow control operations use the data stack, and only two make use of the return address stack, so knowing about stacks is less important in this post than in the others. Knowledge of other assembly language variants would definitely be an asset, as these follow the same patterns found in other processors.

Last Time

The last post covered arithmetic and logic unit (ALU) instructions, which modify the condition code (CC) register. Many of the flow control instructions make use of the CC flags to determine whether or not to move execution flow elsewhere.

Jumps

Jump (jmp, jsr, rts) instructions change the program counter (PC) to an absolute address in memory. They are all unconditional, that is, the change in the PC happens regardless of the system's state.

jmp changes the PC to an address specified as immediate operand to the instruction without side effects.

jsr changes the PC, but pushes the address of the next instruction after jsr to the return address stack. This is paired with rts which pulls the PC from the top of the return address stack. These allow for subroutine calls and returns and allow for more structured programming than jmp or any of the branching instructions.

Branches

Branch instructions use a single byte, twos-complement signed address offset as their operand. This allows for faster changes to the PC, as a single byte can be loaded faster by the CPU. Additionally, except for the unconditional b branch, each branch instruction will check against some CC flag or flags.

Conditional Branches

  • beq - branch on equal
    • branches when the zero flag on the CC is set
  • blt - branch on less-than
    •  branches when the negative flag on the CC is set
  • ble - branch on less-than-or-equal
    •  branches when either the zero or negative CC flags are set
  • bcr - branch on carry
    •  branches when the carry flag on the CC is set
  • bov - branch on overflow
    •  branches when the overflow flag on the CC is set
  • bdiv0 - branch on divde-by-zero
    •  branches when the divide-by-zero flag on the CC is set

At the moment there is no branch-on-underflow instruction, or any greater-than branches. There's space to put them, but I haven't gotten around to it yet.

The End?

That concludes the instruction set portion of these deep dives. Next up is the assembler itself. Included will be the well loved Hello World! example, among others. Full knowledge of all the system calls is not necessary, each one used will be explained as it's used.

Comments

Popular posts from this blog

What Kind of Games?

I started programming when I was young, with the hopes of writing video games. I think a lot of kids start that way. When you like something, or someone, you try to emulate what you’re seeing. But how has that early dream turned out? They tell writers to write what they know. It’s good advice. How can you write about life in the Serengeti without have someone to give you a first hand account or having been there yourself? You can always use your imagination, and that’s all you can really do when writing fantasy or science fiction. It works for writing video games. How can you expect to write a genre you don’t immerse yourself in? These days I spend most of my gaming time playing casual games. I’m busy doing other things, and don’t want to spend long stretches just sitting at the console or computer. Recently I read an article about the kind of video games the most people tend to flock to. Typically they’re games that are relatively simple and involve sorting things in some way. It

Am I Jonesing for the Internet?

I’m feeling a little agitated and jittery today. My internet access is down due to some nasty snow and wind. Are the two related? They might be. I know I’m certainly missing my twitter friends and feeling less in touch with the world. How long is this weather going to hold? I can’t look that up. Sure, I could pull out a radio and listen in, if I had one. I might somewhere, but I’m at the mercy of the broadcaster to decide when to report the weather and how much of it to report. Some argue that internet access should be a basic human right. Does this point of view hold water? I suppose it could be argued that since the internet allows us to draw together into a larger community that it is an essential part of improving the human condition. Its use in political organizing and to connect dissidents in repressive regimes can certainly help make the case for it as a basic human right. Is the jitteriness really from not having the internet? My doctor did just increase my dose of modafi

Aldebaran Colony

This is a quick little story I whipped together one day as a writing exercise. That's mainly the sort of stories I'll be putting up; 1000 word vignettes that I wrote during a day. Here it is: Why they had thought they needed a podiatrist on the colonization team was something Harry Jones couldn’t figure out. He wasn’t even one of the best podiatrists, although he had his moments. It wasn’t as if he wasn’t happy to be along. He was, in fact, overjoyed when he was given the news. It had just come as a bit of a surprise to him that he had been selected to join the ten thousand other people on the colony ship bound for Aldebaran 5. The ship had been equipped with a new Petrescu-drive engine, which would allow them to cross the distance between earth and the Aldebaran system in about 15 seconds. There had been some hushed conversations between the scientists setting up the engines, but Harry was confident that the colonists’ best interests were being kept in mind. After all, it was