Solution:
;code prepare by PAILLA RAGHAVENDRA REDDY;if input is 0A 01 02 0F
;then output is 01 02 0A 0F
TTL transfer
AREA Myprog, CODE, READONLY
ENTRY
EXPORT main
main
LDR R7,=0X1FFFF100 ; initialize the register R7 with starting address.
LDR R1,[R7,R1] ; fetch the first value to R1 for counting.
LSLS R1,R1,#0x02 ; left shift the R1 by 2 position to multiply with 4.
LOOP ADDS R6,R6,#0X04 ; Shift R6 to fetch the next word.
CMP R6,R1 ; compare R6 with R1 to continue loop.
BEQ done ; if R6=R1 than end loop otherwise continue.
LDR R2,[R7,R6] ; store minimum value.
MOVS R0,R2 ; R0 stores the initial value.
LDR R4,=0X00000000 ; R4 stores the address of data when minimum is found.
ADDS R3,R6,#0X04 ; R3 is also counter that starts from next value of R6.
COMPARE LDR R5,[R7,R3] ; fetch data into R5.
CMP R5,R2 ; compare the R5 with R2 to find lesser.
BLO LOWER ; number are unsigned so if R5<R3 than jump to label.
back ADDS R3,R3,#0X04 ; Increment R3.
CMP R3,R1 ; Compare R3 with R1 to continue or exit Compare loop.
BLE COMPARE ; If R3<=R1 continue Compare Loop.
CMP R4,0X00000000 ; If R4 value changed the Goto Swap
BNE SWAP
back1 B LOOP ; unconditional jump to comapre
LOWER MOVS R2,R5 ; transfer R5 to R2 if R5 is higher than R2
ADDS R4,R7,R3 ; Store the address where minimum is found
B back ; jump to label
SWAP STR R0,[R4] ; Swapping
STR R2,[R7,R6]
B back1 ; jump to label
done
SWI &11
END
Input
Result
No comments:
Post a Comment