Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AREA BubbleSort, CODE, READONLY
- ENTRY
- Start
- MOV r0, #0 ; array index being sorted
- MOV r12, #0; whether there haven't been any swaps
- ADR r1, DataStart ; get data start address
- ADR r2, DataEnd ; get data end address
- MOV r12, #0
- ADD r5, r0, #4
- MOV r9, r1
- ADD r5, r9, #4
- Loop
- LDR r3, [r9]
- LDR r4, [r5]
- CMP r3, r4
- STRGT r3, [r5]
- STRGT r4, [r9]
- MOVGT r12, #1
- ADD r9, r9, #4
- ADD r5, r9, #4
- CMP r2, r5
- BNE Loop
- CMP r12, #1
- BNE EndSort
- B Start
- EndSort
- CMP r1, r2
- BEQ Stop
- LDR r0, [r1], #4
- SVC 2
- B EndSort
- ; **** One way to use the SVCs
- ; **** (as sub-routine calls to the SVCs)
- DumpRegs
- SVC 1 ; debug command to dump all registers
- MOV pc, lr ; return to calling sub-routine
- PrintR0
- SVC 2 ; debug command to printR0
- MOV pc, lr ; return to calling sub-routine
- Stop
- BL DumpRegs ; print all the registers
- SVC 0 ; stop the emulator
- ; *** The data values to be sorted
- ; *** Multiple DCDs per line support NOT needed
- DataStart
- DCD -4
- DCD 2
- DCD 5
- DCD 910
- DCD 10
- DCD -12
- DCD 91
- DCD 11
- DataEnd
- END
Advertisement
Add Comment
Please, Sign In to add comment