ATTiny13 Assembler Simulator
It's been quite a journey for me so far with the ATTiny13 - when they first arrived in the mailbox back in 2016 I fell about the place laughing at their physical size (■) and also their limitations in terms of processing power and memory.But the price kept me coming back - in 2017 I could pick up 50 or so of these little fellas for around AU$18. Now in 2020 they are still a reasonable AU$25 or so. Originally I used the Arduino IDE and language with various cores available at the time to program them - but I did brick a few of them because I did not really understand fuses and other AVR dark arts.
A lot of reading and reading and reading later I learned about fuse setting and then made the switch to programming in assembler. I started to really enjoy the challenges and rewards of these chips with their perfect combination of price and power for most of my projects. They also slept real well when asked to, and used hardly any energy going about their business, particularly when I learned how to successfully run them at 128kHz.
Recently on this blog I wrote about an ATTiny13 project that included PWM and also "random" number generation. Before that I recently looked at the electronic components that maximise the energy use for the same project.
In both those blogs I glossed over the assembler programming bit, but I thought that it might be useful to spend a little bit of time looking at the code working at the bare metal level through the lens of Gerhard Schmidt's amazing AVR simulator
At the heart of the blog today (and video) is a focus on the values in the registers of the AVR while the program is stepping through each assembler instruction. A couple of years ago I didn't really understand what a "register" was, and I would have given anything to "see" the registers in action. It is always more educative to link abstract and concrete - and using avr_sim in this way makes it possible.
Whilst I could spend hours stepping through the code today, I really wanted to concentrate on the random number generator, and also how the values are shifted around in the registers and manipulated by the code.
This is probably not the best way to write AVR assembler, but the teacher in me says that it might be easily understandable for a beginner. The useful part I believe is the ability to repeat the video a few times and keep an eye on different register values while at the same time matching up the assembler instructions.
Even better - download avr_sim, load the code into the simulator and step through each command yourself to watch it tick over "in real life"!