Kenbak-1 Shift and Rotate Instructions


Introduction to Kenbak-1 Shift and Rotate Instructions

Kenbak-1 Shift and Rotate Instructions allow us to manipulate data at a memory location by moving bits around within a byte. Specifically, the “A” or “B” Register. This is a 1-byte instruction.

Not only is this good for cosmetic appearance of your project, but also of good use for industry. For instance, we can track a bad part down a conveyor.

There is not much memory in the Kenbak-1, so it’s important to understand all of the commands that are available. This keeps us from having to manually write code to perform some complex tasks. Obviously, less code equals less memory. We only have 256 bytes available (total)!

In this section, we’ll discuss how these shift and rotate instructions work, and show some program examples.

I would encourage you to download and print some programming worksheets for the Kenbak-1 as you read through this post.

Kenbakuino

Shift Instruction

We can shift the A or B register to the left or right. Additionally, we can shift 1, 2, 3, or 4 positions. For these examples, we’ll simply discuss single shifts of one position.

When we shift the bits to the right, bit #7 remains stale. That is to say, it remains at it’s last value. Bit 0 is effectively “lost”. When we shift the bits to the left, a 0 will shift into bit #0. The value that was previously in bit 7 is lost.

Example of left shift:

Initial Value: 10 000 000

After first shift: 11 000 000

After three shifts: 11 110 000

Rotate Instruction

Again, we can rotate either the A or B register. For this example, we’ll perform a left rotate. When we rotate all of the bits to the left (one by one), the value of bit #7 will load into bit #0. Likewise, when we shift the bits to the right, the value of bit #0 will load into bit #7.

Example of left rotate:

Initial Value: 10 000 000

After first rotate: 00 000 001

After three rotates: 00 00 100

Building the Instruction:

Let’s discuss how to build our instruction:

Bit #7:  0 for Right, 1 for Left
Bit #6:  0 for Shift, 1 for Rotate
Bit #5:  0 for A Register, 1 for B Register
Bit #4 & #3:  01 for 1 Place, 10 for 2 places, 11 for 3 places, and 00 for 4 places
Bit #2:  0 Always off for these instructions
Bit #1:  0 Always off for these instructions
Bit #0:  1 Always on for these instructions

If we wish to perform a right rotate on the “A” Register for 1 position, our code will be: 01 001 001 (111 octal)

Test a Program for the Kenbak-1 Shift and Rotate Instructions

Let’s try a program that sets bit #7, then performs a right rotate continuously.

If it works, your bit should continuously rotate from the left side of your display to the right. At that point, it will start again on the left side.

I’m trying this out on the Kenbakuino, so I had to slow down the processor to see it. To slow down your program press stop, then hold 7 while pressing stop again. Next press start.

For more information, visit the Kenbak-1 Category Page!

— Ricky Bryce

For Customized automation training, visit my employer's website at http://atifortraining.com!

Leave a comment

Your email address will not be published. Required fields are marked *

84  −    =  eighty three