sortstring
MOV r0, r1 ; save the contents of r1
MOV r2,#12 ; the size of the string
MOV r3,#1 ; the counter for the outer loop
mainloop
MOV r8,#0 ; variable that holds if a swap has occured
CMP r3, r2 ; see if the loop counter matches the string size
BGE endsort ; jump to the end of the subroutine
MOV r9, #0 ; set the inner loop counter
MOV r10, #12
SUB r10, r10, #r3
sortloop
CMP r9, r10 ; see if r9 and r10 match
BGE endloop ; if r9 >= r10 then exit this loop
LDRB r4,[r1],#1 ; load a byte (or character) into r4
LDRB r5,[r1] ; load the byte next to r4 into r5
CMP r4,r5
BLE skipsort ; if r4 > r5
STRB r4,[r1],#-1 ; write the updated charaters to srcstring
STRB r5,[r1]
MOV r8, #1 ; indicatea a swap has occured
skipsort
ADD r1, r1, #1 ; increment the address that r1 points to
ADD r9,r9,#1 ; increment the inner loop counter
B sortloop ; jump back to the top
endloop
CMP r8,#0
BEQ endsort ; if no swap occured finish the program
ADD r3,r3,#1 ; increase the outer-loop counter
B mainloop ; jump to the main loop
endsort
MOV r1, r0 ; restore the pointer to the string
MOV pc, lr ; return
cheers for your help
Jon
My ARM assembler woes...
So earlier on I was saying how I didn't mind doing some ARM assembler, I have now changed my mind.
I've had to write a sorting program that takes my name and sorts it alphabetically...I started 12 hours ago and I just can't figure out whats wrong. It seems that its looping through and sorting once so it sorts the character next to it but thats it! Its real late and I'm a beaten man I could literally cry over this now...so I was wondering if anyone could look through the routine and see where its going wrong?
Quote:Original post by Jonny_SLDRB r4,[r1],#1 ; load a byte (or character) into r4 LDRB r5,[r1] ; load the byte next to r4 into r5... STRB r4,[r1],#-1 ; write the updated charaters to srcstring STRB r5,[r1]
(In my best Homer voice)Mmmm... Arm
In doing a quick look over the code, It would appear that r4 is being moved two spots backwards, and r5 is being put back where it came from.
I think you want:
LDRB r4,[r1] ; load a byte (or character) into r4 LDRB r5,[r1],#1 ; load the byte next to r4 into r5... STRB r4,[r1],#1 ; write the updated charaters to srcstring STRB r5,[r1]
[Edited by - cdoty on May 16, 2007 11:13:19 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement