Click here to download

While teaching unsigned and signed binary integers, I wrote these programs so that the students can run them and see overflow in action. There are four programs- addu, adds, subu and subs- for adding and subtracting 8-bit unsigned and signed integers. The numbers to be added are given as arguments when running the program. The result is printed on the screen and also saved in a file, which can be opened with a hex editor to see the result in binary format.

While the students where running the programs they obviously had questions about the the dot-slash. That was a good opportunity to tell them that all the commands they run, ls or cd or chmod or anything for that matter, are all executable files residing somewhere in the file system. I made them type which ls and find that ls is actually /bin/ls.

I pointed out the interesting fact that ls, which was somewhere else in the filesystem, could be run by just typing ls and not necessarily /bin/ls, while the addu program which was right here in this folder you needed to specify that it is in the current folder (they knew that dot stands for the current folder). Then I showed them how by adding the current directory to the PATH variable, you could run it by just typing addu, like any other command in the system.