tcepsa: (JuggleGeese)
[personal profile] tcepsa
Today has been a very good day at work so far; I've rewritten a portion of code that used a bunch of cumbersome "if" checks to take advantage of the fact that JavaScript supports try/catch blocks. Now I just do what I want to do, and if it doesn't work then I fix it and move on. The fun part is that they're nested three levels deep, but in pretty much all cases I can actually recover from whatever broke it, fix the thing that caused it to break, and move on. No more shall I be at the mercy of (this particular aspect of this particular set of) data architecture!

As it turns out, that was just an appetizer :) I've always been fascinated by low-level programming, stuff like assembly language where you can go in and manipulate the CPU registers and such, or operating system code that you can look at and see how the CPU switches between processes. Having the ability to wield that amount of control is very attractive to me. On the other hand, it takes forever to do almost anything at that level, and it is ridiculously easy to make a mistake that will bring the entire system crashing down on you. So through a combination of impatience, lack of time, conviction that someone else had already done it better, and sheer terror that I would irrevocably corrupt my hard drive, melt my CPU, and/or somehow cause my computer to explode, I never really did too much in the way of low level programming. There was one exception, that being my embedded systems class back in college (to this day quite possibly my most favorite class ever). Still, I learned about the concepts, more or less, and one of the things that I picked up on was recursion.

Most of the time recursion is done by calling a function that then calls itself as part of its execution, until some condition is met (if you want to know more details about why someone might find this useful, let me know; it's not really within the scope of this entry ;) However, in this particular case I decided that I didn't want to do it that way. Maybe it was because I felt that I already had too many functions. More likely I just wanted to see if I could come up with something that would accomplish the same goal without having to rely on a function that calls itself.

I did. For the first time (probably since that embedded programming class, though possibly ever) I used a stack of my own creation. It worked pretty much exactly how I would think of a computer calling functions, or switching processes. It stored all of the relevant state data in an object (frame) and pushed that frame onto the stack. It then moved down a level in the tree that I was processing by loading the state variables with the information pertaining to that level. When it was done with that level, it popped the frame off of the stack and loaded its state variables, thereby moving to the next level up. It was tricky to make sure that the counters incremented in the right places to make sure I didn't miss anything, but it's working like a charm.

Sure, I probably could have done it more easily with the usual recursive function strategy, but I think I got a deeper understanding both of how recursion works and how computers work by doing it this way ^_^

Date: 2007-01-04 08:07 pm (UTC)
From: [identity profile] nminusone.livejournal.com
I love the low-level stuff too. I started out doing hardware and embedded systems but there isn't as much of that work anymore and I definitely miss it. I find myself doing pointless geeky projects at home just so I can work with wires and assembly language again. :)

Date: 2007-01-04 09:33 pm (UTC)
From: [identity profile] tcepsa.livejournal.com
I know what you mean. I've got a PIC programmer that I occasionally tinker with, and I have delusions of creating my own CNC mill someday... ;)

Date: 2007-01-04 10:50 pm (UTC)
From: [identity profile] nminusone.livejournal.com
As much as I love machine code, I hate PIC assembly language. Out of the many I've seen PIC is easily the worst. The newer versions are better, but still... ick! If you'd like to try 68hc11 I have a bunch of dev boards for that, you could have one if you like. 6811 is like 6809, or liks 6502 expanded to 16 bits, with a Motorola flavor. ;)

OMGSQUEEEEEE!!!

Date: 2007-01-04 11:26 pm (UTC)
From: [identity profile] tcepsa.livejournal.com
"68hc11" as in "Motorola 68hc11"? If I remember correctly, that's the chip on which my embedded systems class was based! I'd love a dev board!!! It would be like Christmas in January! ;)

Re: OMGSQUEEEEEE!!!

Date: 2007-01-04 11:56 pm (UTC)
From: [identity profile] nminusone.livejournal.com
Yup, that's the one. I think every embedded systems class ever used that CPU! The board I have is the non-Forth version of the the NMIY-0020 from www.newmicros.com . I can't find a direct link but it's on their site under 68hc11. I'll have to dig up all the bits and pieces but you're welcome to whatever I can find. What I do not have: their monitor program or any higher level languages (my project didn't use it), but they sell all that stuff individually too for $10-$20.

Profile

tcepsa: (Default)
tcepsa

April 2015

S M T W T F S
   12 34
567891011
12131415161718
19202122232425
2627282930  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 31st, 2026 02:24 pm
Powered by Dreamwidth Studios