This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
notes:comporg:fall2023:projects:bia0 [2023/09/10 21:11] – created wedge | notes:comporg:fall2023:projects:bia0 [2023/10/26 00:33] (current) – [Arrays of Structs in Assembly] walley | ||
---|---|---|---|
Line 1: | Line 1: | ||
======BIA0====== | ======BIA0====== | ||
+ | ====Arrays of Structs in Assembly==== | ||
+ | In Breakout coded in C, we used an array of brick structs to keep track of all the bricks on the field. When porting over to assembly, the approach needs to be changed due to a multitude of factors. | ||
+ | Arrays don't formally exist in assembly. Since in array is simply an unchanging space of sequential memory, the stack must include the data for all the bricks in order. For breakout, each brick has five properties: | ||
+ | - X-axis Position | ||
+ | - Y-axis Position | ||
+ | - Color | ||
+ | - Health | ||
+ | - Visibility Toggle | ||
+ | |||
+ | Accessing an individual array element uses an ID value to get that position' | ||
+ | |||
+ | The first Brick' | ||
+ | < | ||
+ | mov R0, BP | ||
+ | isub R0, 24 | ||
+ | mov R10, R0 | ||
+ | </ | ||
+ | |||
+ | Within our for-loop we use to access all the bricks sequentially, | ||
+ | |||
+ | When moving from one brick to the next, we directly adjust the memory address stored in R10. It's simple in practice: | ||
+ | < | ||
+ | isub R10, 5 | ||
+ | </ | ||
+ | This reference point moves from the current Brick' |