What you learn today
- poke writes to an address
- sp stays put
- Use the stack as a table
With push and pop the stack works like a pile of plates. Sometimes, though, you want to write to a particular place without clearing away everything above it. That is what poke is for.
poke writes to an address
poke 5 293.15 # address 5 = 293.15
get r0 db 5 # r0 = 293.15
poke address value writes the value straight to the address. You read it with get r? db address, which you already know. Neither changes sp.
| Instruction | writes / reads | sp |
|---|---|---|
push value | at address sp | grows by 1 |
pop r? | from address sp − 1 | shrinks by 1 |
poke adr value | at address adr | stays |
put db adr value | at address adr | stays |
get r? db adr | from address adr | stays |
poke adr value and put db adr value do the same. poke is shorter, put can also write into the stack of other devices.
The stack as a table
With fixed addresses the stack becomes a table. An example: five light programmes for the bar, each with one colour:
poke 0 Color.White
poke 1 Color.Blue
poke 2 Color.Green
poke 3 Color.Orange
poke 4 Color.Red
Filling sits before the start label and runs once. In the main loop a get is then enough:
lbn prog DIAL HASH("Barlicht") Setting Average
get colour db prog
The dial position is directly the address in the table.
An address above 511 reports StackOverFlow, a negative one StackUnderFlow. If the address comes from outside, for instance from a dial, limit it beforehand with max and min. NaN does not belong in an address either, catch it first.
If you mix push and poke in the same stack, put the table at fixed addresses far up, such as from 400. The push pile grows upwards from 0 and will not get in its way so soon.
Diagram
Exercise
Task
Five light programmes for the bar. The dial “Barlicht” picks the programme 0 to 4, the LEDs “Bar” (StructureDiode) get the colour.
- Before the start label fill the table with
poke: 0Color.White, 1Color.Blue, 2Color.Green, 3Color.Orange, 4Color.Red. - In the loop read the colour from the table with
get. - Limit the position to 0 to 4. If the dial is missing, programme 0 applies.
spstays 0 throughout.
Hints
Hint 1
Five poke lines before start:.
Hint 2
Replace NaN with 0 using snan and select, then max … 0 and min … LAST.
Hint 3
get colour db prog fetches the colour without changing sp.
Quiz
4 questions. You pass from 60 % – the server does the grading.
Complete the day
- Passed the simulator exercise
- Passed the quiz with at least 60 %
Without an account progress is saved in this browser only.
Report a mistake in this lesson
Please sign in to report. Sign in