Solution 2:
; Another version of finding maximum and minimum from given list.
; This style of coding is based on dividing logic into small function and functions are called from main.
; This style of coding is bit matured and it is more understandable than armature style coding.
; Code is prepared by sohan patel
TTL transfer
AREA Myprog , CODE,READONLY
ENTRY
EXPORT main
main
LDR R1,=0x1FFFF100 ; initialize R1 with starting address
LDR R2,[R2,R1] ; load value of addr r1 into r2
LSLS R2,R2,#0x02 ; multiply it by 4
ADDS R2,R2,R1 ; give address upto last location
ADDS R1,R1,#0x04 ; add 4 for staring at 1FFFF104
LDR R3,=0x00000000 ; intialize r3 with MIN value
LDR R4,=0xFFFFFFFF ; intialize r4 with MAX value
CMPR
CMP R2,R1 ; compare r2,r1
BCS loop1 ; if (r2>=r1) then loop1
BCC done ; if (r1<r1) then end
loop1
LDR R5,[R5,R1] ; load the value
ADDS R1,R1,#0x04 ; add 4 to r1
CMP R5,R3 ; compare r4,r3
BCS task1 ; if (r4>=r3) then task1
BCC min ; if (r4<r3) then min
min
CMP R5,R4 ; compare r5,r4
BCS task2 ; if (r5>=r4) then task2
BCC task3 ; if (r5<r4) then task3
task1
MOV R3,R5 ; move the value of r5 into r3
B min ; goto min
task2
LDR R5,=0x00000000 ; intialize r3 with 0
B CMPR ; goto CMPR
task3
MOV R4,R5 ; move the value of r5 into r4
LDR R5,=0x00000000 ; intialize r3 with 0
B CMPR ; goto CMPR
done
SWI &11
END
Input:
Result: