home | |||
links |
|
||
developer's mag main page article part 1 part 2 part 3 part 4 part 5 part 6 part 7 part 8 part 9 |
2 - Anatomy of a FunctionKey to writing ebm assembly code is adhering to the programming conventions regarding registers. The registers of a well-behaved function look like this:
Variable Needs Although register data is convenient and fast, sometimes it isn't enough. Some code only needs a few registers, while other code can use the parameter values as workspace. Then there's code that needs local storage, and for that the stack is ideal: ; make room on stack for local variables ldc -OFFSET ; constant - must be multiple of 4 add sp ; add stack pointer value mov t,sp ; move back & protect spaceNote that OFFSET is negative because the stack grows downward. Once allocated, we can access the data: ldc VAR_OFFSET ; offset to variable add sp mov (t),r0 ; or some other instruction...Finally, remember to clean up: ; make room on stack for local variables ldc OFFSET ; now positive-we are returning the space add sp ; add stack pointer value mov t,sp ; move back & free up Previous Section Next Section |
||
Copyright © 2001-2006 ebmDevMag.com - Legal Notice |