Wednesday, January 16, 2008

Tracing Code, Specially Assembly

well, the second exam was Micro-Processors, i really liked this course, and i think i made some good work at it too, the exam went ok, i just didn't feel good about that strange looking question that weighted slightly above 1/5 the total mark, it listed some PIC16F84 code and asked u to trace, describe and fix the functionality it provides, the exam was over when a friend of me showed up saying "hey, it's a factorial, isn't it?" well, buddy, it didn't look like a factorial to me!! and it got much better with the more "factorial" u hear as u go,

now, let me tell u something, whenever u trace any non-trivial piece of code, u must use a table (with borders) of variables and update them step-by-step,

another thing, those pieces of asm codes usually evaluate to something meaningful, specially when u're asked to describe or name it, something like "a*b", "factorial", "pow(a,b)", "Σ ai" or other simple math formulae, maybe that's because nobody writes code that just looks ugly, it's usually written to make something good,

problem is, i did make some sort of a table, i had a row that looked like [3, 2, 1] and the other (that's what u evaluate) started with [4], then u multiply successive elements and update the second, so i just messed it up in the third loop and ended with [4, 12, 36, 36] so the result of foo1(4) was "36", not "24", because i should have multiplied 12 "by 2 not by 3",

maybe i'll remember that for the rest of my life...

No comments: