Now, right before we get to programming, we need to understand that there are formats that we must conform to. For writing your own OS, this usually amounts to an IVT. If you're going to write a program that can be run by an existing OS, you must conform to some sort of standard laid out by that OS provider. Fortunately for you, most programming tools do this for you, if you conform to their standard format. If you want more information, some great examples (both of how they work and how unnecessarily difficult they can be) look into "MZ executable (DOS)," "Portable Executable (Windows)," and "Executable and Linkable Format (Linux and a few other)." I've worked with ELF directly, and I've glanced at PE. All I can say is, while messing with them yourself instead of letting the tools do it, you can often shrink your programs by vast amounts (wasteful padding and such, and it can take away the advantages of caches, which is why Intel made x86 processors got such a huge boost from doubling the cache size), but the headache isn't worth it and you probably won't be able to do it in a commercial setting, since it can have a huge impact on development time the first time you do it (and also, you wouldn't be able to use things like C++ and such if you did).

First you're going to need a "target machine," or something that you want to make programs for. While writing this, I was originally planning on x86, but it's already next to impossible to get 32bit code running on it. ARM is also not a good choice: android and iPhone are cutting 32bit support, soon, which means modern 64bit will be abandoned at some point, too. Arduinos are cheap, and they'll get cheaper. Also, it's pretty close to the level you've been learning so far. Right now, the average price seems to be about 10 US dollars, with the cheapest being about 4 US dollars and the most expensive being about 30 US dullars. The good news is, you can get an emulator, too. For windows, use simutron, but keep in mind that it runs slower than realtime on some computers (if this is the case, we can lower the delay values for our testing code to speed things up). I hear simavr is decent for Linux (it's the backend of simutron), but I'm not sure how to use it. You'll want to set a "probe" on "B5." If looking for an alternative, be careful of the wording: for arduino, the community at large has created a separation between "simulator" and "emulator." The "simulators" take in uncompiled code, which is in a format that we won't be using.

Next, unless you actually want to memorize opcodes and encodings, we will want to get some pre-made programs that remembers all that junk for us. For that, there's avr-gcc for windows (Atmel seems to be publishing prebuilt windows version to this site which doesn't seem to like external links, so you'll have to use the search function, or pray and hope this link works, still), and for linux, just find your own version. In the future, there's hope of llvm/clang getting something going, so those of you on linux/android, you have that to look forward to, in which case all you need to do is figure out how to make it happen, since you wouldn't need to download or install any other programs, but it's still in the works. For particularly clever people, try an android version.

Lastly, you'll want a good text editor. For linux and android, vim is a great choice. For windows "notepad" usually comes standard, though it's a real pain since it has limited "undo" capabilities. Notepad++ was popular when I started programming, and it's around today, so it seems like a good choice for the future as well. I'll let you find your own. The important thing is that it has to be a raw text editor, meaning it cannot support bold and other formatting. A good way to check is to see if this stays bold if you copy and paste it into your editor. If it looks like all other text, then it'll most likely suffice.

So, to put this all together, you're going to need to be able to type "avr-gcc" and get a response that it doesn't have a source file. Odds are, if you're on linux, you can already do this from whatever terminal you use, so you can skip this paragraph (test to make sure, but if not follow as if you're using windows). For windows users, you're going to want to find a permanent spot for avr-gcc. First, you'll want to extract the archive, and you take that whole folder and move it to the location where you want it (you'll want everything that's in that folder, so don't just grab the bin folder). Next, you'll have to (and since this constantly changes with windows) research on how to add something to your "PATH variable." You want the bin folder added to your PATH variable. If you did this correctly, you should be able to open up "command prompt" (may have to search how to do that, too) anywhere and type "avr-gcc" and it'll complain about not having any input/source files. If you see that message, you're golden.

You'll want to download this. I included a file called "open_terminal.bat" which, if double clicked, will work on most versions of windows and open a terminal window right there. If you type "make" and hit enter, it'll create 3 files if it worked. If you have a real arduino hooked up "make flash" should work. If not, you'll want to change "COM5" to whatever the arduino's real port is. In windows, the device manager should show you if you can find the arduino in it. For linux, you're going to have to change this, regardless. Usually it's /dev/tty/USB0 or /dev/tty/ACM0. If you're using an emulator, you'll want to stick that probe or LED, depending on what's available, on pin B5. If that's not enough, you're probably using an LED and it has an in and an out, at which point you want to add a resister (if they're available, but if not it probably doesn't simulate the burning) and then connect it to ground. If your LED still doesn't work, either the emulator's borked, you didn't load the right program (or at all), or you hooked the LED up backwards (since it is a type of diode). You'll notice in the makefile that there is an option that, if there's a folder called avrhexdir, you can run it on android (as long as you have the pre-compiled avr-gcc and friends) and then use a secondary app to upload it. As of right now, the apps are slowly being made to do this. If you see blinking/flashing, you're good (if you're not sure, you can watch this painful video I made while really sleepy).

Get your own web kitty here!
┬ęCopyright 2010, 2011, 2012, 2013, 2014, 2017, 2018. All rights reserved.