Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 1.39 KB | None | 0 0
  1.                 .text
  2.                 .global _start
  3.  
  4. // 1. calculate the maximum
  5. // 2. calculate the minimum
  6. // 3. calculate max - min
  7. // 4. bit-right-shift twice
  8.  
  9. // R0 := maximum
  10. // R1 := minimum
  11. // R2 := the number of items left to iterate through
  12. // R3 := the address of the current number in the list (pointer)
  13. // R4 := the actual number pointed to by R3
  14.  
  15. _start:
  16.             LDR     R2, N       // set R2 to length of list
  17.             LDR     R3, =NUMBERS // pont R3 to first element in list
  18.             LDR     R0, [R3]    // set max and min as the first element
  19.             LDR     R1, [R3]
  20.  
  21. MINMAX:     SUBS    R2, R2, #1  // decrement N by 1
  22.             BEQ     CALCSTDEV   // if N = 0 then GOTO CALCSTDEV
  23.             ADD     R3, R3, #4  // else move pointer to next number
  24.             LDR     R4, [R3]    // load the number into R4
  25.             CMP     r4, r0      // compare with current max
  26.             MOVGT   R0, R4      // if R4 > R0 then max = R4
  27.             CMP     R4, R1      // compare with current min
  28.             MOVLT   R1, R4      // if R4 < R0 then min = R4
  29.             B       MINMAX
  30.  
  31. CALCSTDEV:  SUB     R3, R0, R1  // R3 := MAX - MIN
  32.             MOV     R3, R3, ASR #2
  33.             STR     R3, =STDEV
  34.  
  35. STDEV:      .word   0   // final result
  36. N:          .word   10  // length of data list
  37. NUMBERS:    .word   4, 5, 3, 27, 1, 18, 2, 6, 10, 23    // list of data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement