Add ES/Lab/LAB5/INSERTION.asm
This commit is contained in:
parent
9343c63874
commit
c37a788cbd
1 changed files with 50 additions and 0 deletions
50
ES/Lab/LAB5/INSERTION.asm
Normal file
50
ES/Lab/LAB5/INSERTION.asm
Normal file
|
@ -0,0 +1,50 @@
|
|||
AREA RESET, DATA, READONLY
|
||||
EXPORT __Vectors
|
||||
__Vectors
|
||||
DCD 0x10001000
|
||||
DCD Reset_Handler
|
||||
ALIGN
|
||||
|
||||
AREA MYCODE, CODE, READONLY
|
||||
ENTRY
|
||||
EXPORT Reset_Handler
|
||||
|
||||
Reset_Handler
|
||||
LDR R0, =ARRAY
|
||||
MOV R9, #9
|
||||
LDR R9, [R9]
|
||||
ADD R9, R0, R9, LSL #2 ; address of one element from the end
|
||||
ADD R1, R0, #4 ; i pointer
|
||||
|
||||
OUTER
|
||||
CMP R1, R9 ; checks append if counter
|
||||
BGE DONE
|
||||
|
||||
LDR R5, [R1]
|
||||
MOV R2, R1 ; j pointer (inner loop)
|
||||
|
||||
INNER
|
||||
SUB R2, R2, #4 ; decrements j to previous element
|
||||
CMP R2, R0
|
||||
BLT INSERT
|
||||
|
||||
LDR R8, [R2]
|
||||
CMP R8, R5
|
||||
BLE INSERT
|
||||
|
||||
STR R8, [R2, #4]
|
||||
ADD R1, R1, #4
|
||||
B INNER
|
||||
|
||||
INSERT
|
||||
STR R5, [R2, #4]
|
||||
ADD R1, R1, #4
|
||||
B OUTER
|
||||
|
||||
DONE
|
||||
B DONE
|
||||
|
||||
AREA mydata, DATA, READWRITE
|
||||
ARRAY DCD 5,2,8,1,9,4,6,3,7
|
||||
|
||||
END
|
Loading…
Add table
Add a link
Reference in a new issue