Adsense

Showing posts with label Assembly. Show all posts
Showing posts with label Assembly. Show all posts

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

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 counter=0;

if (counter > 10){             //condition checking grater than allow to loop
counter =0;}
else {                                    //less than 10 counter += 1
counter = counter +1;}

return (0);
}

Result:


Assembly language code:

TTL transfer
        AREA Myprog, CODE, READONLY
ENTRY
        EXPORT main
main
        MOVS R1,#9            ;Initilize the value with 9
        CMP R1, #10         ; compare to 10
        BLE incr_counter     ; if less or equal, then branch
        MOVS R1, #0         ; counter = 0
        B counter_done         ; branch to counter_done
incr_counter
        ADDS R1, R1, #1     ; counter = counter +1
counter_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...