Execution cycle
The code inside the .text
segment is executed entirely at the beginning of each tick. Each millisecond of execution costs 1 kJ of energy. The execution time is rounded down to the nearest integer meaning that the first 999μs are 'free'. The execution will halt when there is not enough energy available (but the first 999μs are always executed) or when execution time exceeds 20ms*.
After each tick, all FLAGS are reset.
*about 960,000 instructions in game server (2.4 GHz, single core)
See also: Battery Hardware
CPU Architecture
Work in progress
General purpose registers
The registers are 16-bits locations available to the CPU and are used in some instructions and system calls.
Register | Purpose |
---|---|
A | General |
B | General |
C | General |
D | General |
X | General |
Y | General |
BP | Base pointer |
SP | Stack Pointer |
Read Basic Assembly Tutorial for more information.
The FLAGS register
The FLAGS register holds the status - information about the last executed instruction - of the CPU. The FLAGS register cannot be read or written directly. There are 5 flags that can modified or read by instructions (Read Instruction set to learn which instructions modifies the FLAGS register):
Flag | Description |
---|---|
CF (Carry flag) | Relevant for unsigned operations. Indicates that there was a carry out of the most significant (leftmost) bit |
ZF (Zero flag) | Indicates that the result of an operation is 0 |
SF (Sign flag) | Indicates that the most significant (leftmost) bit of the result of an operation is set |
OF (Overflow flag) | Relevant for signed operations. Indicates that the sign of the result of an signed operation is wrong (See examples below) |
BF (Break flag) | Tells the CPU to stop the execution. This flag is set with the BRK instruction. |
Carry Flag
The carry flag is set when there is a carry out of the destination's most significant bit
For example:
+ 1111 1111 1111 1111 # Signed:-1 Unsigned: 65535
0000 0000 0000 0001 # Signed: 1 Unsigned: 1
-------------------
0000 0000 0000 0000
Note that the result of the result of the previous operation is perfectly valid for signed numbers (See Basic Assembly Tutorial) but it is invalid for unsigned operations.
Sign flag
The sign flag is set when the most significant (leftmost) bit of the result of an operation is set.
For example:
+ 0100 0000 0000 0000 # Signed: 16384 Unsigned: 16384
0100 0000 0000 0000 # Signed: 16384 Unsigned: 16384
-------------------
1000 0000 0000 0000 # Signed:-32768 Unsigned: 32768
^
Sign flag is set
Overflow flag
The carry flag is set when the signed two's complement result of an operation does not fit in the destination, or more specifically, when there is a carry/borrow into or out of the most significant (leftmost) bit, but not both.
The overflow flag is set when the result of an addition of two positive numbers is negative or when the result of an addition of two negative numbers is positive.
For example:
There is a carry out of the most significant (leftmost) bit, OF is set.
v
+ 1111 1111 1111 1111 # Signed:-1 Unsigned: 65535
1000 0000 0000 0000 # Signed:-32768 Unsigned: 32768
-------------------
0111 1111 1111 1111 # Signed: 32768 Unsigned: 32768
There is a carry out of the most significant bit
\ There is also a carry into the most significant bit, OF is not set
VV
+ 1111 1111 1111 1111
1100 0000 0000 0000
-------------------
1111 1111 1111 1111
There is also a carry into the most significant bit, OF is set
V
+ 0100 0000 0000 0000
0100 0000 0000 0000
-------------------
1000 0000 0000 0000