Adsense

Showing posts with label Embedded C. Show all posts
Showing posts with label Embedded C. Show all posts

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

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

Steps to find the maximum from given set of 32 bit data

 

Step 1:

- Initialize register with the memory location 0x1FFFF100 i.e. R7 for holding base address.

- Initialize 0x00000000 to any of the register for holding Shift value i.e. R6. We need to add 0x04

In case, of 

Word we need to ADD 0x04

half word ADD 0x02 and

byte ADD 0x01.

- Initialize 0x00000000 to any of the register for holding maximum value i.e. R3.


Memory transfer

Step 2:

- Fetch 32 bit data from next memory location and initialize to any of register for the looping i.e. R1. 

- Add 0x04 into base address(0x1FFFF100) to now start fetching from 0x1FFFF104.

Step 3:

- Fetch next data (32bit) and store to any register i.e. in R2.

- Fix any of the register to store maximum number from list i.e. in R3

Arithmetic 

Step 5:

Compare content of both registers mentioned above.

Step 6: 

if the content of Data register (R2) is higher than content of maximum no register(R3) than transfer the content of data register(R2) into max register(R3).

Conditional branch

Step 7:

- Repeat steps 3 and 6 also decrease the looping register(R1) 

- Continue up to the value stored in Step 2 i.e. register R1 goes to zero.

 

Repeat above Steps to find the minimum from given set of 32 bit data.

 

Note:

if you are facing any doubt, please ask the query in comment section

Write embedded C and assembly code to understand program flow instructions for "for loop".

Usually, we start coding with assembly and than we move to the embedded C code. In this case we first understand the  embedded C code and than we will write the equivalent assembly code to mimic the same thing.

Embedded C code:

int main ()
{
volatile unsigned int total, i;

total = 0;                    // initialize the total
        for (i=0;i<5;i=i+1)
        {
        total = total + i;
        }
return(0);
    
}

       
 Result:

 

Assembly language code:

        TTL transfer
        AREA Myprog, CODE, READONLY
ENTRY
        EXPORT main
main
        MOVS R2, #0 ; Total = 0
        MOVS R1, #0 ; i = 0
loop
        ADDS R2, R2, R1 ; Total = Total + i
        ADDS R1, R1, #1 ; i = i + 1
        CMP R1, #5 ; compare i to 5
        BLT loop ; if less than then branch to loop
done
        SWI &11
        END

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...