Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.66 KB | None | 0 0
  1.  PRESERVE8
  2.     THUMB
  3.     GET       config.s
  4.     GET       stm32f10x.s
  5.  
  6.     AREA      RESET, CODE, READONLY
  7.  
  8.     DCD       STACK_TOP
  9.     DCD       Reset_Handler
  10.  
  11.     ENTRY
  12.  
  13. Reset_Handler    PROC
  14.     EXPORT    Reset_Handler
  15.  
  16. main
  17.     MOV32     R0, 0x20000200        ; R0 - array start (arr)
  18.     MOV       R1, #50               ; R1 - array size (size)
  19.     MOV       R2, #0                ; R2 - array position (pos)
  20.     MOV       R3, R1                ; R3 - half of array size (half_size)
  21.     ASR       R3, #1                ; R3 == 25
  22.  
  23. loop
  24.     CMP       R2, R3                ; while (pos != half_size)
  25.     BLNE      swap
  26.  
  27.     B         loop
  28.  
  29.     ENDP
  30.  
  31. swap          PROC
  32.     ;  l-->         <--r  - left and right positions (l, r)
  33.     ; [0 1 2 3 ... 48 49] - array
  34.     MOV       R4, R0                ; R4 - address of l
  35.     MOV       R5, R2                ; R5 == pos
  36.     ADD       R4, R5                ; R4 == arr + pos
  37.  
  38.     MOV       R5, R0                ; R5 - address of r
  39.     MOV       R6, R1                ; R6 == size
  40.     SUB       R6, R2                ; R6 == size - pos
  41.     SUB       R6, #1                ; R6 == size - pos - 1
  42.     ADD       R5, R6                ; R5 == arr + (size - pos - 1)
  43.  
  44.     LDR       R6, [R4]              ; R6 - l
  45.     LDR       R7, [R5]              ; R7 - r
  46.  
  47.     MOV       R8, R6                ; R8 - tmp, R8 == l
  48.     BFI       R6, R7, #0, #8        ; l = r
  49.     BFI       R7, R8, #0, #8        ; r = l
  50.     STR       R6, [R5]              ; *(address of r) = l
  51.     STR       R7, [R4]              ; *(address of l) = r
  52.  
  53.     ADD       R2, #1                ; pos++
  54.  
  55.     BX        LR
  56.     ENDP
  57.  
  58.     END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement