Shifting meanings: "Spaghetti Code"?

Ethan Dicks ethan.dicks at
Thu Aug 16 20:42:20 CDT 2007

On 8/16/07, Jim Leonard <trixter at> wrote:
> On Thu, Aug 16, 2007 at 01:06:11PM -0400, Sridhar Ayengar wrote:
> > Although, I might consider assembler code where every second instruction
> > is a jump to be spaghetti code.
> Actually, I'd consider the opposite.  In assembler with something
> like:
> cmp ax,01
> je  @1
> cmp ax,02
> je  @2
> ...etc, at least you know what the value is that is causing the
> jump.  With a jump table, you have to do some digging.

One hardware engineer I used to work with on several classic products,
used the same technique, no matter the platform...

cmp #'1
bne @2
pages of code for the selection matching "1"
br top_of_loop
2: cmp #'2
bne #3
pages of code for the selection matching "2"

...etc.  It was page after page of assembler with no vertical
formatting breaks, no headers, no useful comments.  I saw this
technique on more than one product this guy worked on.  I had to clean
up the mess later.  :-P  (I used a jump table ;-)

> I'm still going to code jump tables, obviously, but the former is
> easier to understand to someone looking at the code for the first time.

An undocumented jump table can indeed be confusing, as can building
one with generic labels.  My technique is to have a banner comment
explaning what the table is about, then a smaller multi-line banner at
each label so that you can see where one section stops and the next
one starts.


More information about the cctech mailing list