Part A
1. ALP to multiply two 16 bit binary numbers.
Theory:
Mnemonics used:
MUL, LDR,STR,BX: write explanation for these mnemonics
/*A main code calls the assembly code. A global variable by name "globvar" is declared at main in C code is loaded at asm code using the variable address.
*Basically extern keyword extends the visibility of the C variables and C functions.
*extern explicitly for C variables when we want to declare them without defining them
*to know more about extern visit:https://www.geeksforgeeks.org/understanding-extern-keyword-in-c/
*/
/*********************************c file*******************************************/
#include <LPC17xx.h>
extern void MULTIPLY(void); //MULTIPLY:Name of assembly routine
extern unsigned long int globvar; //global variable to access at asm code
unsigned long int globvar,result;
#include "LCD.h"
int main(void)
{
SystemInit();
MULTIPLY(); //Function Call
result = globvar;
LCD_DISP(globvar);
while(1);
}
/*********************** ALP file or .s file ******************************************/
AREA MULTI , CODE , READONLY
EXPORT MULTIPLY
IMPORT globvar
MULTIPLY
LDR R0,=0X706F ; load 16 bit no. to R0
LDR R1,=0X7161 ; load 16 bit no. to R1
MUL R2,R1,R0 ; multiply R1 with R0 and store result in destregister R2
LDR R3,=globvar ; load the addr of globvar into R3
STR R2,[R3] ;load the result present in R2 to memory location whose addr is in R3
BX LR ; Branch and exchange Link register content [jumps back to C code]
END
*********************************************************************************
Download program:two 16 bit binary numbers Multiplication
2. ALP to find the sum of first 10 integer numbers.
Theory:
Mnemonics used:
/*A main code calls the assembly code. A global variable by name "globvar" is declared at main in C code is loaded at asm code using the variable address.
*Basically extern keyword extends the visibility of the C variables and C functions.
*extern explicitly for C variables when we want to declare them without defining them
*to know more about extern visit:https://www.geeksforgeeks.org/understanding-extern-keyword-in-c/
*/
/*********************************c file*******************************************/
#include <LPC17xx.h>
extern void sumten(void); //sumten :Name of assembly routine
extern unsigned long int globvar; //global variable to access at asm code
unsigned long int globvar,result;
#include "LCD.h"
int main(void)
{
SystemInit();
sumten(); //calling asm code
result = globvar;
LCD_DISP(globvar);
while(1);
}
/*********************** ALP file or .s file ******************************************/
THUMB
AREA sum,CODE,READONLY
EXPORT sumten
IMPORT globvar
ENTRY
sumten
MOV R1,#10 ; load 10 to register
MOV R2,#0 ; empty R2 register to store result
loop
ADD R2,R2,R1 ; add the content of R1 with result at R2
SUBS R1,#0x01 ; Decreament R1 by 1
BNE loop ; repeat till R1 goes 0
LDR R0,=globvar ; load the addr of var into R0
STR R2,[R0] ; store the result into addrs location
BX LR ; jumps back to C code
END
*********************************************************************************
Download program:sum of first 10 integer numbers
1. ALP to multiply two 16 bit binary numbers.
Theory:
Mnemonics used:
MUL, LDR,STR,BX: write explanation for these mnemonics
/*A main code calls the assembly code. A global variable by name "globvar" is declared at main in C code is loaded at asm code using the variable address.
*Basically extern keyword extends the visibility of the C variables and C functions.
*extern explicitly for C variables when we want to declare them without defining them
*to know more about extern visit:https://www.geeksforgeeks.org/understanding-extern-keyword-in-c/
*/
/*********************************c file*******************************************/
#include <LPC17xx.h>
extern void MULTIPLY(void); //MULTIPLY:Name of assembly routine
extern unsigned long int globvar; //global variable to access at asm code
unsigned long int globvar,result;
#include "LCD.h"
int main(void)
{
SystemInit();
MULTIPLY(); //Function Call
result = globvar;
LCD_DISP(globvar);
while(1);
}
/*********************** ALP file or .s file ******************************************/
AREA MULTI , CODE , READONLY
EXPORT MULTIPLY
IMPORT globvar
MULTIPLY
LDR R0,=0X706F ; load 16 bit no. to R0
LDR R1,=0X7161 ; load 16 bit no. to R1
MUL R2,R1,R0 ; multiply R1 with R0 and store result in destregister R2
LDR R3,=globvar ; load the addr of globvar into R3
STR R2,[R3] ;load the result present in R2 to memory location whose addr is in R3
BX LR ; Branch and exchange Link register content [jumps back to C code]
END
*********************************************************************************
Download program:two 16 bit binary numbers Multiplication
2. ALP to find the sum of first 10 integer numbers.
Theory:
Mnemonics used:
/*A main code calls the assembly code. A global variable by name "globvar" is declared at main in C code is loaded at asm code using the variable address.
*Basically extern keyword extends the visibility of the C variables and C functions.
*extern explicitly for C variables when we want to declare them without defining them
*to know more about extern visit:https://www.geeksforgeeks.org/understanding-extern-keyword-in-c/
*/
/*********************************c file*******************************************/
#include <LPC17xx.h>
extern void sumten(void); //sumten :Name of assembly routine
extern unsigned long int globvar; //global variable to access at asm code
unsigned long int globvar,result;
#include "LCD.h"
int main(void)
{
SystemInit();
sumten(); //calling asm code
result = globvar;
LCD_DISP(globvar);
while(1);
}
/*********************** ALP file or .s file ******************************************/
THUMB
AREA sum,CODE,READONLY
EXPORT sumten
IMPORT globvar
ENTRY
sumten
MOV R1,#10 ; load 10 to register
MOV R2,#0 ; empty R2 register to store result
loop
ADD R2,R2,R1 ; add the content of R1 with result at R2
SUBS R1,#0x01 ; Decreament R1 by 1
BNE loop ; repeat till R1 goes 0
LDR R0,=globvar ; load the addr of var into R0
STR R2,[R0] ; store the result into addrs location
BX LR ; jumps back to C code
END
*********************************************************************************
Download program:sum of first 10 integer numbers
No comments:
Post a Comment