Tuesday, 11 June 2013

Addition of two 32 bit numbers with subroutine & function in assembly and embedded c language respectively (LPC2148).



AIM: Addition of two 32 bit numbers, with subroutine in assembly language and with function     in embedded c language.

THEORY:
Basically Arithmetic logical unit (ALU) is main important part of the processor. ALU used for performing various arithmetic as well as logical operations. If result of ALU is zero then Z flag of CPSR register will set. If carry is generated from 31th bit of the result then carry flag will set. If 31th bit of the result is 1 then negative flag will set.The arithmetic instructions implement addition and subtraction of 32-bit signed andunsigned values.

PORCEDURE:
For creating project, we need to take following steps.
1) Create new project
2) Algorithm
3) Simulation of Algorithm
These three steps are involved in procedure.

1) Create new project
1.   Select a new project and give particular name to that project. e.gADD
2.   Select chip NXP (founded by Philips) LPC2148.
3.   For assembly language don’t add startup file and for embedded c language add startup file.
4.   Select a new editor file, write logic in that file and save it by using .asm extension in assembly language and .c extension in embedded c language.

2) Algorithm
Algorithm consists of following steps.
In assembly language:
1.   Take first 32 bit value in register R0.
2.   Take second 32 bit value in register R1.
3.   Write branch instruction for subroutine.
4.   Do addition in subroutine and store result in R3 register.
5.   Move content from PC to LR and come back from subroutine.
In embedded c language:
1.   Include header file.
2.   Declare function for addition
3.   Call function in body of main program after declaration of variables.
4.   Write a function of declared function.

3) Simulation of Algorithms
It consists of following steps.
1.   After writing program just build it.
2.   If there are any errors, they will be due to some mistake in typing the program. To locate the error, double click on the first error. Check for the error and remove it. Repeat this till all errors are gone.
3.   Now it’s time to debug. Click on the debug tab and debug program. Check the contents of the registers in assembly language programming and contents of the variables in embedded c programming.

OBSERVATIONS:
Assembly language
1.   Content of R0 register is:   …………………..
2.   Content of R1 register is:   …………………..
3.   After addition result in R3:   …………………
4.   Content of LR after subroutine call:  ……………….
5.   Content of PC after jumping from subroutine:  …………………….



Embedded C language
1.   Content of variable a is:  …………………….
2.   Content of variable b is:  …………………….
3.   After addition result of variable temp:  …………………….




Addition of two 32 bit numbers in assembly as well as in embedded c
In Assembly:
            AREA ADDITION, CODE, READONLY
            ENTRY
START
            MOV R0, #05
            MOV R1, #03
            BL JUMP
            SWI 0x11
JUMP
            ADD R2, R0, R1
            MOV PC, LR
END



In Embedded c:
#include <LPC214X.H>
int tmp;                                    //global variable
void addition (int a, int b);       //declaration of function
int main ()
{
            int a,b;
            a=3;                                         //body of main program
            b=4;
addition (a,b);
}                                                          // end main

void addition (int a,int b)                     //function of declared function
{
            tmp=a+b;
}
 

No comments:

Post a comment