Esi Programs Part 1
Esi Programs Part 1
Keil µvision 4
Browseandcreateanewprojectintherequiredlocation
Selectthetargetdevice(here,LPC1768fromNXP)fromthelistortypetheexactnameofthe
device.PressOK.
Translatetheprogrambyselecttheiconfromtoolbarorfrommenubar.
STEP 10;Checkforerrorsandwarningsinthebottomwindow .
STEP 11; Ifnoerror,Select“Build”iconfromtoolbarorfrommenubar.
StartthedebugsessionfromMenubar.
PressOK
14
PressfunctionkeyF11orselect“step” optionunderDebugmenuforsinglestep
executionand verify the output inregister window/Memory window/xPSR.
ASSEMBLY CODE:
ORG 000H
MOV A,#00H
MOV R0,#40H
MOV R1,#05
LABEL: ADD A,@R0
INC R0
DJNZ R1,LABEL
MOV R2,A
END
INPUT:
I40:01 I41:02 I42:03
I43:04 I44:05
OUTPUT:
R2:0F
ADDITION OF TWO ARRAYS
ASSEMBLY CODE:
ORG 000H
MOV RO,#50H
MOV R1,#60H
MOV R2,#05
LABEL: MOV A,@R0
ADD A,@R0
MOV @R0,A
INC R0
INC R1
DJNZ R2,LABEL
END
INPUT
I50:01 I50:02 I50:03 I50:04
150:05I60:02 I61:02 I62:03
I63:04 I64:05
OUTPUT:
I50:02 I51:04 I52:06 I53:08 I54:0
MULTIPLICATION OF 2-16BIT NUMBER
ASSEMBLY CODE
INC R0 MOV
@RO,AEND
CODING
A ALP TO MOVE A BLOCK OF DATA FROM CODE TP RAM MEMORY
AREAReset,DATA,READONLY
EXPORTVectors
Vectors
DCD0X20001000
DCDReset_Handler;
AREAwritedata,CODE,READONLY
src DCD
0x11,0X22,0X33,0X44,0X55
ENTRY
EXPORT
Reset_Handler
Reset_Handler
LDR
r0,=srcLDR
r1,=dst
MOVr2,#5
l1 LDRr3,[r0],#4
STRr3,[r1],
#4SUBSr2,
#1 BNE l1
StopBstop
AREAdata,DATA,READWRITE
dst DCD0X0
EN
AREAReset,DATA,READONLY
EXPORTVectors
Vectors
DCD0X20001000
DCDReset_Handler;
AREAwritedata,CODE,READONLY
srcDCD0x11,0X22,0X33,0X44,0X55
ENTRY
EXPORT
Reset_Handler
Reset_Handler
LDR
r0,=srcLDR
r1,=dst
MOVr2,#5
l1LDMIAr0!,{r4-r8}
STMIAr1!,{r4-r8}
SUBS r2,#1
BNE l1
StopBstop
AREAdata,DATA,READWRITE
Dst DCD 0X0
END
INPUT:00000011h,00000022h,00000033h,00000044h,00000055h.
OUTPUTatdst:
00000011h,00000022h,00000033h,00000044h,00000055h.
ADDTION OF TWO 16-BIT NUMBERS
Input: Output:
movr0,#0dch //lowernibbleofNo.1
movr1,#0feh //highernibbleof
No.1
movr2,#34h //lowernibbleofNo.2
movr3,#12h //highernibbleof
No.2
clr //
c
mova,r0
subba,r2
mov22h,a
mova,r1
subba,r3
mov21h,a
mov00h,c
end
Trywithdifferentdata.Ex:(Smallernumber) –(larger number).
movr0,#34h
/5678*1234movr1,#12h
mov
r2,#78hmo
v
r3,#56hmo
va,r0mov
b,r2mulab
mov
33h,amov
r4,b mov
a,r0 mov
b,r3 mul
ab
add a,r4
mov r5,a
mov a,b
addc
a,#00hmo
vr6,amov
a,r1 mov
b,r2 mul
abadd
a,r5
mov
32h,a
mova,b
addc
a,r6mov
00h,cmo
vr7,a
mova,r3
movb,r1
mul ab
adda,r7
mov
31h,amo
va,b
addc
a,20hmo
v
30h,aend
Writethe logic ofthe program. Trywithsome otherlogic.
mathematicaloperationsinaCprogram.Theycanbeusedinprogramstodefine
expressionsandmathematicalformulas.TheCarithmeticoperatorsarethesymbolsthat
areusedtoperformmathematicaloperationsonoperands.Thereareatotalof9
arithmeticoperatorsinCtoprovidethebasicarithmeticoperationssuchasaddition, subtraction,
multiplication, etc.
1.
2.
The C Arithmetic Operators are of two types based on the number of operands
theywork. Theseare asfollows:
TheCbinaryarithmeticoperatorsoperateorworkontwooperands.Cprovides
BinaryArithmeticOperatorsforperformingarithmeticfunctionswhichareasfollow
Subtraction
res=a-b;//
subtraction
printf("a - b
is%d\n",res
);
res=a*b;//
multiplication
printf("a * b
is%d\n",res);
res=a/b;//di
vision
printf("a/bis
%d\n", res);
res=a%b;//modulus
ais10andbis
4a + b is 14
a-bis6 a
* b is
40a/bis
2
a%bis2
The unary arithmetic operators operate or work with a single operand. In C, we
havetwounaryarithmeticoperatorswhichareasfollows:
UnaryPlusOperator Returnsthevalueofitsoperand. +h
Unary Returnsthenegativeofthevalue
Minus ofitsoperand. -h
Operator
The operator is used to increment the value of an integer. It can be used in two
ways:
When placed before the variable name (also called thepre-incrementoperator), its
value isincremented instantly.Consider the example: a = ++x;
Thisexamplecanbeexpandedtoa=(x=x+1);
The operator is used to decrement the value of an integer. Just like the
incrementoperator, the decrement operator can also be used in two ways:
When placed before the variable name (also called the operator),
itsvalueisdecrementedinstantly.Forexample, .
printf("ais%dandresultis%d\n",a,res);
//pre-decrementexample:
//resisassigned10onlysinceaisupdatedhere
//itselfres=
--a;
//aandreshavesamevalues=10 printf("a is
%d and result is %d\n", a, res);
printf("ais%dandresultis%d\n",a,res);
//pre-decrementexample:
//resisassigned10onlysinceaisupdatedhere
//itselfres=
--a;
//aandreshavesamevalues=10 printf("a is %d
and result is %d\n", a, res);
return0;
}
PostIncrementand
Decrementa is 11 and
Result is 10
ais10andresultis11
Pre Increment and
Decrementais11and result
is 11
ais10andresultis10
constintled1=6,led=7,led=8;intdelayalue=
1000;voidsetup()
{
pinMode(led,1);//HIGH=1andINPUT=0pinMode(led2,
OUTPUT);pinMode(led3, OUTPUT);
}
voidloop()
{
digitalWrite(led1,1);//HIGH=1means5voltsdigitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);delay(delayvalue);
digitalWrite(6,0);//LOW=0means0voltdigitalWrite(7,LOW);
digitalWrite(8, LOW);delay(delayvalue); delayvalue== 50;
if(delayvalue == 0)
delayvalue=1000;
}