Adsense

Write Embedded C code to find maximum minimum from given list of 32 bit data stored from memory location 0x1FFFF138 onwards. No of data elements will be stored on memory location 0x1FFFF134.

 #include<MKL25Z4.h>

int main()
{
volatile unsigned int size,i,k=0xFFFFFFFF,t=0; // t stores max number , k store min number
volatile unsigned int z[]={0x04,0x0A,0x01,0x02,0x0F}; // data taken in array

size = z[0];    // take size from first location

            for (i=1;i<=size;i++)
            {    
            if (t<z[i])    {    t=z[i];    } // find maximum
            if (k>z[i]) {    k=z[i];    } // find minimum
            }    
}

Input:

 

Result:


 

solution of assembly code to find the maximum and minimum from block of 32 bit data stored from memory location 0x1FFFF104, No. of data elements is stored on memory location 0x1FFFF100.

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:

Write a ARM cortex M0+ assembly language code based on arithmatc and logical instructions.

 Problem 1: Implement following code conversions to convert binary no 0x89ABCDEF(32-bits) into a) BCD (64-bits)   b) Gray (32-bits) Problem...