• 10
• 10
• 12
• 12
• 14
• entries
222
606
• views
590319

# Structs and sensible variable layout

837 views

When developing an assembly program, you need to 'declare variables' by attaching an address (in RAM) to a label.

The problem here, of course, is having to calculate all the relevant positions in RAM for each variable. For example,
ram = $C000 ; Assume RAM starts at address$C000var1 = ram+0var2 = ram+1var3 = ram+3 ; var2 is 2 bytes!; ... and so on ...

Now this is fairly painful. So, I added .varloc and .var directives to Brass:
ram = $C000 ; Assume RAM starts at address$C000.varloc ram, 1024 ; 1024B in size.var 1, var1.var 2, var2.var 1, var3; ... and so on ...

This eases things a bit, but what if you have lots of variables and a number of different RAM areas? Now you still have to shuffle things around to fit. So, now, Brass allows you to define multiple areas of memory for variables (through multiple .varloc statements) and shuffles around all the variables to best fit in the available memory. Variables defined using .tempvar can even overwrite eachother (provided they are in different, not-nested modules) to save space.

Of course, sometimes you need variables to share consecutive areas of RAM, so I also added structure support.
; Define it.struct Point2D    .var db, X    .var db, Y.endstruct; Use it.var Point2D, Me    ld a,10    ld (Me.X),a        ld a,32    ld (Me.Y),a        ld hl,10+32*256    ld (Me),hl; Or even:.struct Point3D    .var Point2D, P    .var db,      Z.endstruct.var Point3D, You    ld a,(You.P.X)

And, to comply with the picture requirement, have something ancient and completely unrelated.

## 1 Comment

OMG! A dream come true from my youth, real Hungry Hungry Hippos!