Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

Need help from expert. Simple program sorting arrays from low to highest.

$
0
0

For some reason I can't figure out how to do this properly, I been thinking about this for at least a week, I'd really appreciate any help I could get. I need to sort the array1 and put it in array1s, the same thing with array2 and putting the sorted array in array2s.

Here's what I have:

 

           .text                           ; Assemble into program memory
            .retain                         ; Override ELF conditional linking
                                            ; and retain current section
            .retainrefs                     ; Additionally retain any sections
                                            ; that have references to current




                                         ; section
;-------------------------------------------------------------------------------
ARY1 .set  0x0200
ARY1S .set 0x0210
ARY2 .set 0x0220
ARY2S .set 0x0230




RESET       mov.w   #__STACK_END,SP         ; Initialize stackpointer
StopWDT     mov.w   #WDTPW|WDTHOLD,&WDTCTL  ; Stop watchdog timer


;-------------------------------------------------------------------------------
ClEAR clr r4
clr r5
clr r6




Sort1 mov.w #AR1,R4
mov.b @R4+,R5
mov.w #AR1S,R6
call #Sort


Sort2 mov.w #AR2,R4
mov.b @R4+,R5
mov.w #AR2,R6
call #Sort


Sort clr r7
clr r8
clr r9
clr r10
clr r11
clr r12
clr r13
clr r14
clr r15


clr r10
mov.b R5,R11
dec R11


mov.b @R4+,R7
mov.b @R4,R8
cmp.b R7,R8
jz No_Swap
jge No_Swap


Swap mov.b R7,R9
mov.b R8,R7
mov.b R9,R8
inc R10
mov.b R8,0(R4)
mov.b R7,-1(R4)


No_Swap dec R11
tst R11
jnz Swap
cmp.b #0,R10
jnz Swap
ret


Mainloop jmp Mainloop




ARRAY1SET mov.b   #10,0(R4)
mov.b #20,1(R4)
mov.b #89,2(R4)
mov.b #-5,3(R4)
mov.b #13,4(R4)
mov.b #63,5(R4)
mov.b #-1,6(R4)
mov.b #88,7(R4)
mov.b #2,8(R4)
mov.b #-88,9(R4)
mov.b #1,10(R4)


ARRAY2SET mov.b #10,0(R4)
mov.b #90,1(R4)
mov.b #-10,2(R4)
mov.b #-45,3(R4)
mov.b #25,4(R4)
mov.b #-46,5(R4)
mov.b #-8,6(R4)
mov.b #99,7(R4)
mov.b #20,8(R4)
mov.b #0,9(R4)
mov.b #-64,10(R4)
 
Help please.
-Daniel R

Viewing all articles
Browse latest Browse all 2077

Trending Articles