The chip has no “declare a variable”. Instead there are registers: fixed storage slots that hold one number each.
The register bank
| Register | Purpose |
|---|---|
r0 … r15 | free for your values |
sp (= r16) | stack pointer, see the stack lesson |
ra (= r17) | return address for subroutines |
When the chip is inserted, every register is 0. A register keeps its value until you write something new into it.
Writing numbers
All IC10 values are decimal numbers. There is no separate true and false – those are simply 1 and 0.
| Notation | Example | Value |
|---|---|---|
| Decimal | 42, -7, 293.15 | as written |
| Hexadecimal | $1F | 31 |
| Binary | %1010 | 10 |
| Constant | pi | 3.14159… |
The decimal separator is the dot: 293.15. A comma is read as a thousands separator – 1,5 becomes 15.
The chip does not understand exponent notation like 1e5. Write 100000.
An example
move r0 101.325 # standard pressure in kPa
move r1 $FF # 255
move r2 %1111 # 15
move r3 -12.5
Underscores are allowed in hex and binary numbers and make long numbers easier to read: %1010_0101.
Diagram
Exercise
Task
Fill four registers:
r0= 15r1= 31, but written in hexadecimalr2= 10, but written in binaryr3= −2.5
Hints
Hint 1
Hex numbers start with $, binary numbers with %.
Hint 2
31 is 1F in hex, 10 is 1010 in binary.
Hint 3
For −2.5 use the dot: -2.5.