Advertisement
informaticage

Untitled

May 9th, 2018 (edited)
2,357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MPASM 2.64 KB | None | 0 0
  1. * Samuel Finocchio - 255380
  2. * 09/05/2018
  3. * Excercise 3
  4.  
  5. ; Looping until reaching GUARD
  6. GUARD EQU 3
  7.  
  8. STRUCT_OFFSET EQU 8
  9. ENERGY_OFFSET EQU 0
  10. TAC_OFFSET EQU 4
  11. DEC_OFFSET EQU 6
  12.      
  13. START:
  14.     ; Using D0 as index
  15.     CLR d0
  16.    
  17.     ; Using D1 as total
  18.     CLR d1
  19.    
  20.     ; Using D2 as x0
  21.     CLR d2
  22.    
  23.     ; A0 pointing to X
  24.     MOVE.L #X, a0
  25.    
  26.     ; Addres of a2 is the string
  27.     MOVE.L #s, a2
  28.    
  29. WHILE_LOOP:
  30.  
  31.     ; Compares the string A2 of Index D0: A2[D0] to 'T'
  32.     cmpi.b #'T', (a2,d0)
  33.    
  34.     ; Jumps to Dekyon case if true
  35.     BEQ TAKYON_LABEL
  36.    
  37.     ; Compare the string A2 of Index D0: A2[D0] to 'D'
  38.     cmpi.b #'D', (a2,d0)
  39.    
  40.     ; Jumps to Takyon if true
  41.     BEQ DEKYON_LABEL
  42.  
  43.     ; If none of the above is true we jump to the end of the while loop
  44.     BRA END_WHILE_LOOP
  45.  
  46.     DEKYON_LABEL:
  47.         ; Cloning A0 in A3 to 'easily' work with the indexing
  48.         MOVE.L a0, a3
  49.        
  50.         ; Adding 6 bytes offset to read the Dekyon attribute in the struct
  51.         ADD.L #DEC_OFFSET, a3
  52.        
  53.         ; Copying the first 2 bytes starting from the offsetted memory address to the x0 index to read the Dekyon attribute
  54.         MOVE.W (a3), d2
  55.        
  56.         BRA LOOP_DEFAULT
  57.        
  58.    
  59.     TAKYON_LABEL:
  60.         ; Cloning A0 in A3 to 'easily' work with the indexing
  61.         MOVE.L a0, a3
  62.        
  63.         ; Adding 4 bytes offset to read the TAKYON attribute in the struct
  64.         ADD.L #TAC_OFFSET, a3
  65.        
  66.         ; Copying the first 2 bytes starting from the offsetted memory address to the x0 index to read the takyon attribute
  67.         MOVE.W (a3), d2
  68.        
  69.         BRA LOOP_DEFAULT ; Added for simmetry ( No need )
  70.        
  71.     LOOP_DEFAULT:
  72.         ; Incrementing index d0 (i)
  73.         ADDI #1,d0
  74.        
  75.         ; Cloning A0 in A3 to 'easily' work with the indexing
  76.         MOVE.L a0, a3
  77.        
  78.         ; Size multiplied by the x0 index
  79.         MULS #STRUCT_OFFSET, d2
  80.        
  81.         ; Offsetting by x0 * 8 the X struct
  82.         ADD.L d2, a3
  83.        
  84.         ; A3 now pointes to X[x0]
  85.        
  86.         ; 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)
  87.         ADD.L (a3),d1
  88.        
  89.         ; Indexing the next element of the struct array A0, adding 8 bytes ( sizeof (struct array) )
  90.         ADD.L #8,a0
  91.        
  92.         ; Loops again
  93.         BRA WHILE_LOOP
  94.        
  95. END_WHILE_LOOP:
  96.    
  97.     ADDI #10,d0
  98.  
  99.    
  100.     SIMHALT
  101.    
  102. ; Struct declaration
  103. x: dcb.b 800,$00
  104. ; Char array declaration
  105. s: dc.b  'T','D','T'
  106. ; Declaring total
  107. total: ds.l 0
  108.  
  109.     END    START
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement