Presentation is loading. Please wait.

Presentation is loading. Please wait.

LMC Tricks Common patterns. Single General Purpose Register "Features" – Accumulator only stores most recent value – Add/Subtract look for second value.

Similar presentations


Presentation on theme: "LMC Tricks Common patterns. Single General Purpose Register "Features" – Accumulator only stores most recent value – Add/Subtract look for second value."— Presentation transcript:

1 LMC Tricks Common patterns

2 Single General Purpose Register "Features" – Accumulator only stores most recent value – Add/Subtract look for second value in memory Real world – Processors have multiple registers – Never enough for what you want to do

3 Single General Purpose Register Recipe: – Any time you get a new piece of info, store it Input… store Calculate answer…store – Sometimes you can skip, better safe

4 Order Subtraction must have first operand in accumulator Recipe for X – Y: – Make sure Y is stored in memory – Input/Load X – Subtract Y

5 Branch on Not Zero Want to do things when value is not zero – Use branch to skip code when accumulator = 0 Recipe 1.Do stuff to calculate value 2.Branch if = 0 to step 5 3.Must not be zero, do special stuff here 4.Must not be zero, do special stuff here 5.This happens no matter what

6 Branch on Zero Want to do things when value is zero – Shield always branch with conditional one Recipe: 1.Do stuff to calculate value 2.Branch if = 0 to step 4 3.Branch always to 5 (must not be 0) 4.Special stuff only do with positive value 5.Always do this

7 Repeat Branch to an earlier point causes loop Recipe to repeat while a value >= 0: 1.Do one time setup work 2.… 3.Do stuff to calculate new value 4.… 5.Branch if >= 0 to step 3 (Are we still >= 0? If so repeat) 6. We are done!


Download ppt "LMC Tricks Common patterns. Single General Purpose Register "Features" – Accumulator only stores most recent value – Add/Subtract look for second value."

Similar presentations


Ads by Google