Project 1, Part 1: Assembler

Written by Emmanuel Schanzer

To the tune of: America the Beautiful, by Katherine Lee Bates>

note: pronounce the $r registers by number; eg. $6 "six"

Song is based on source code solution to Project 1, Problem 1: 24-bit to 16-bit pixel conversion

The Solution to Part 1, sung to the tune of "America the Beautiful."
(make sure to pronounce $6 as "six", for example)

To compress a twenty four bit
pixel into sixteen
We used three registers as temp           # $8, $9, and $10 are temp
And drank a bottle clean!                 # we each had 7 or 8 shots of
Assembler, Assembler!                     # vodka when coding this
God shed his grace on thee
And crown thy good with brotherhood
We wish we'd code in C!

From $4 we read, to $5 we write           # $4 points to 24bit array
our pixel when complete!                  # $5 points to 16bit array
In $6 we store our end address            # rather than use a counter,
For comparisons sweet!                    # just check if our next pixel
Assembler, Assembler!                     # is read from the end.
God mend thine every flaw,
With careful, precise stack control,
We'll type our fingers raw!

To calculate register six                 # to find the end addr, just
we shift left by just two                 # mult the num of elements by 4
One word per element for kicks            # (a full word) and add it to
And now we'll start the loop!             # to the start address
Assembler, Assembler!
May God thy gold refine
Till offsetting by an address
Is ingrained in our minds!

Compare $4 with our end address           # recap: if we're reading from
Branch if equivalent                      # the end, branch to done
If not, then $4 has failed the test       # if not, load the next pix
Load the next pixel in!                   #into $8
Assembler, Assembler!
Bestow thy grace on me.
And crown thy good with brotherhood
Maybe we don't need C!

Shift right: chop garbage blues from $8   # 3 rightmost are crap. lose 'em
Shift right again and store,              # align needed green bits in $9
And by 1F to filter straight              # keep only first 5 bits in $8
What's not blue we ignore!
Assembler, Assembler!
God shed his grace on thee
Till souls wax fair as earth and air
Which registers are free?

Shift $9 by seven right and store         # $10 contains only red bits:
The red bits into $10                     # 00000000000RRRRR
Filter by three-E-zero, $9                # Keep only second 5 bits in $9
Shift $10 left A and then....             # align needed red bits:
Assembler, Assembler!                     # 0RRRRR0000000000
God shed his grace on thee!
Till paths be wrought through
wilds of thought
By hacker foot and knee

Or $9 and $10 (that's red and green)      # $9 contains 0RRRRRGGGGG00000
Then or them with our blue                # $8 contains 0RRRRRGGGGGBBBBB
Now $8 contains only 16
We store our pixel new!                   #store it back at addr in $5
Assembler, Assembler!
God shed his grace on thee
Till mem'ry hits no longer bring
Instruction latency!

Add to $5 sixteen bits: that's two        # increment $5 by a half-word
To $4 add a whole word                    # inc. $4 to next pixel
Jump back and we shall start anew         # jump to loop
We're done and have you heard...
Assembler! Assembler!
God shed his grace on thee
Till nobler men keep once again           # "Take another shot, Walter."
We'll never code in C!                    # "You too, Emmanuel.

Back to the Cornell CS Songbook