This is the third post in this series and will cover arithmetic and logic unit (ALU) instructions. The operations are pretty straightforward, and there are few caveats, if any. You can find a table of these instructions at the end of the post.
You can find the first post here, the second here.
Prerequisites
There are a couple of prerequisites to fully understanding this series of posts. It will assume you know what a stack is and that you have some knowledge of assembly language. But the content could still be interesting even without that knowledge. I'll leave it to you to decide.
Last Time
In the last post I covered stack and memory manipulation instructions. Those instructions allowed for manipulation of the values on the stack; shuffling items around, adding items, and removing them. They can be combined with ALU instructions to produce a number of effects.
ALU instructions
These instructions apply mathematical operators to values from the stack. ALU operations operate exclusively on values from the top of the stack, replacing them with the results of the operation. Each of the instructions can modify one of more flags from the condition code (CC) register.
The current shortcomings are the lack of logical and/or, and the lack of any xor instructions. This will be remedied in a future version of the emulator.
Like stack instructions, ALU instructions have single and double byte variants. The double byte versions are formed by adding a w to the instruction mnemonic.
CC register
The CC register contains the following flags:
- overflow - the most recent multiplication operation would require more bits than are available for the current operation size
- negative - the result of the last operation was negative
- carry - the result of the last operation had a carry bit left over
- zero - the result of the last operation was zero
- underflow - the most recent division operation generated a result lower than 1, higher than -1, but not 0
- divide by 0 - the most recent division instruction attempted to divide a number by 0
Next Time
For the next post I'll cover the branching instructions. I'm guessing those will take the most explanation, so prepare for a longer post!
Comments