Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- * Samuel Finocchio - 255380
- * 09/05/2018
- * Excercise 3
- ; Looping until reaching GUARD
- GUARD EQU 3
- STRUCT_OFFSET EQU 8
- ENERGY_OFFSET EQU 0
- TAC_OFFSET EQU 4
- DEC_OFFSET EQU 6
- START:
- ; Using D0 as index
- CLR d0
- ; Using D1 as total
- CLR d1
- ; Using D2 as x0
- CLR d2
- ; A0 pointing to X
- MOVE.L #X, a0
- ; Addres of a2 is the string
- MOVE.L #s, a2
- WHILE_LOOP:
- ; Compares the string A2 of Index D0: A2[D0] to 'T'
- cmpi.b #'T', (a2,d0)
- ; Jumps to Dekyon case if true
- BEQ TAKYON_LABEL
- ; Compare the string A2 of Index D0: A2[D0] to 'D'
- cmpi.b #'D', (a2,d0)
- ; Jumps to Takyon if true
- BEQ DEKYON_LABEL
- ; If none of the above is true we jump to the end of the while loop
- BRA END_WHILE_LOOP
- DEKYON_LABEL:
- ; Cloning A0 in A3 to 'easily' work with the indexing
- MOVE.L a0, a3
- ; Adding 6 bytes offset to read the Dekyon attribute in the struct
- ADD.L #DEC_OFFSET, a3
- ; Copying the first 2 bytes starting from the offsetted memory address to the x0 index to read the Dekyon attribute
- MOVE.W (a3), d2
- BRA LOOP_DEFAULT
- TAKYON_LABEL:
- ; Cloning A0 in A3 to 'easily' work with the indexing
- MOVE.L a0, a3
- ; Adding 4 bytes offset to read the TAKYON attribute in the struct
- ADD.L #TAC_OFFSET, a3
- ; Copying the first 2 bytes starting from the offsetted memory address to the x0 index to read the takyon attribute
- MOVE.W (a3), d2
- BRA LOOP_DEFAULT ; Added for simmetry ( No need )
- LOOP_DEFAULT:
- ; Incrementing index d0 (i)
- ADDI #1,d0
- ; Cloning A0 in A3 to 'easily' work with the indexing
- MOVE.L a0, a3
- ; Size multiplied by the x0 index
- MULS #STRUCT_OFFSET, d2
- ; Offsetting by x0 * 8 the X struct
- ADD.L d2, a3
- ; A3 now pointes to X[x0]
- ; A3.L refers to the first 4 bits of A3 (X struct array of position x0) in particular the element energy, the sum is added in d1 (total)
- ADD.L (a3),d1
- ; Indexing the next element of the struct array A0, adding 8 bytes ( sizeof (struct array) )
- ADD.L #8,a0
- ; Loops again
- BRA WHILE_LOOP
- END_WHILE_LOOP:
- ADDI #10,d0
- SIMHALT
- ; Struct declaration
- x: dcb.b 800,$00
- ; Char array declaration
- s: dc.b 'T','D','T'
- ; Declaring total
- total: ds.l 0
- END START
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement