Program to find the largest or smallest number in an array of 32 numbers

Write an Assembly program to find the largest or smallest number in an array of 32 numbers

Program:-

Largest:-

    AREA LARGEST,CODE,READONLY
    ENTRY
    MOV R5,#6
    LDR R1,=VALUE
    LDR R2,[R1],#4
LOOP LDR R3,[R1],#4
    CMP R2,R3
    BHI LOOP1
    MOV R2,R3
LOOP1 SUBS R5,R5,#1
    CMP R5,#0
    BNE LOOP
    LDR R4,=RESULT
    STR R2,[R4]
STOP B STOP
VALUE DCD 0x44444444,0x22222222,0x11111111,0x33333333,0xAAAAAAAA,0x8888888,0x99999999
    AREA INFO,DATA,READWRITE
RESULT DCD 0x00000000
    END

Smallest:-

    AREA LARGEST,CODE,READONLY
    ENTRY
    MOV R5,#6
    LDR R1,=VALUE
    LDR R2,[R1],#4
LOOP LDR R3,[R1],#4
    CMP R2,R3
    BLS LOOP1
    MOV R2,R3
LOOP1 SUBS R5,R5,#1
    CMP R5,#0
    BNE LOOP
    LDR R4,=RESULT
    STR R2,[R4]
STOP B STOP
VALUE DCD 0x44444444,0x22222222,0x11111111,0x33333333,0xAAAAAAAA,0x8888888,0x99999999
    AREA INFO,DATA,READWRITE
RESULT DCD 0x00000000
    END

Leave a Reply

Your email address will not be published. Required fields are marked *