Scanning addresses with loops
Need: write patterned data to a block of addresses and check each one, or find the first address that meets a condition. Building the address from a variable saves writing one step per address.
| Case | What it does |
|---|---|
| Write a pattern | i starts at 0; Repeat 16 times: write 0x0100 + ${i} = ${i} * 0x0101, then i += 1 |
| Check the pattern | Reads the 16 addresses back with another Repeat, also expecting ${i} * 0x0101 |
| Find the first zero | addr starts at 0x0101; While the value at ${addr} is != 0, addr += 1, at most 64 times. Then Log the address |
json
{ "set": { "var": "addr", "value": "0x0101" } },
{ "while": { "address": "${addr}", "compare_op": "!=", "expected": 0, "max_loops": 64 } },
{ "set": { "var": "addr", "op": "+=", "value": 1 } },
{ "endwhile": true },
{ "log": "First register that reads 0: ${addr}" }
After 16 passes, the While reads 0 at 0x0110 (Actual column [@0x0110]), and the Log prints First register that reads 0: 272.
Notes
- Values in the Log and the Variables tab are shown in decimal:
272is0x0110. The Hex column of the Variables tab shows hex. - Always set
max_loopson a While, so a condition that always holds cannot run forever. Going past the limit makes that While step FAIL. - A Read inside a Repeat compares on every pass; if any pass fails, that step is FAIL.
Download the sample script
Sample script
Before running it, start a Slave window on 127.0.0.1:502 and click Listen, then open the script with Open JSON in Script mode and click Run. See How to use the examples.
