Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .text
- .global _start
- // 1. calculate the maximum
- // 2. calculate the minimum
- // 3. calculate max - min
- // 4. bit-right-shift twice
- // R0 := maximum
- // R1 := minimum
- // R2 := the number of items left to iterate through
- // R3 := the address of the current number in the list (pointer)
- // R4 := the actual number pointed to by R3
- _start:
- LDR R2, N // set R2 to length of list
- LDR R3, =NUMBERS // pont R3 to first element in list
- LDR R0, [R3] // set max and min as the first element
- LDR R1, [R3]
- MINMAX: SUBS R2, R2, #1 // decrement N by 1
- BEQ CALCSTDEV // if N = 0 then GOTO CALCSTDEV
- ADD R3, R3, #4 // else move pointer to next number
- LDR R4, [R3] // load the number into R4
- CMP r4, r0 // compare with current max
- MOVGT R0, R4 // if R4 > R0 then max = R4
- CMP R4, R1 // compare with current min
- MOVLT R1, R4 // if R4 < R0 then min = R4
- B MINMAX
- CALCSTDEV: SUB R3, R0, R1 // R3 := MAX - MIN
- MOV R3, R3, ASR #2
- STR R3, =STDEV
- STDEV: .word 0 // final result
- N: .word 10 // length of data list
- 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