My CS301 (Assembly Programming Language) teacher has a brilliant style of teaching. In actuality he's a pretty amazing guy all around. Nice guy, always willing to talk shop about Computer Science, and extremely sharp. Sometimes I need to remind myself that he's still just a man. like me.
Our lesson today started out talking about a cat. We have an array of commands. What if we want it to eat, and what if we want to specify what it eats? We have two options. We can have an array of parameters to go with these commands. But what if some commands don't have parameters? What do we do?
Or, and this is a slightly better solution. What if we have one array, and if we want parameters after a command, put them after the command to be processed, and then go on? Now we have one array, and now we have commands and parameters as needed if we know what commands need parameters.
Well, this is still a little bit confusing. How about an example (in my own handrolled pseudocode here)
let cat_cmds be an array of words
initialize cat_cmds to "sleep", "wake", "eat", "Friskies", "Meow", "sleep", "exit"
From here, we can loop through the array, and knowing that the command "eat" will take a parameter, we can step through the array and process the command, and then we can move on. When we reach the exit command, we close down the program.
Why do this convoluted example? Well...
If you change these commands to byte codes, make a function pointer to that array, and then call the function, you have a function out of machine code, because this is how computers are coded.
It was pretty beautiful. I don't think that, if he had simply launched into a lecture about bytecodes without first drawing a parallel that we could have understood a lot easier. It was interesting to learn that this is how computers work under the hood. I think I'm starting to see the big picture. Computers don't really understand anything. They just process information into human readable formats.
Yeah, that's right.
They're dumb as rocks.
Friday, September 17, 2010
Subscribe to:
Comments (Atom)