0% found this document useful (0 votes)
22 views27 pages

Esi Programs Part 1

Lab program

Uploaded by

harishvaran64
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views27 pages

Esi Programs Part 1

Lab program

Uploaded by

harishvaran64
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

SOFTWARE REQUIREMENTS

Keil µvision 4

SOFTWARE HANDLING PROCEDURE

STEP1; Doubleclick onµvision4iconinthedesktop


Select“New µvisionProject”fromprojectinthe menubar.

Browseandcreateanewprojectintherequiredlocation
Selectthetargetdevice(here,LPC1768fromNXP)fromthelistortypetheexactnameofthe
device.PressOK.

CopystartuptoProjectfolder andaddtoprojectfile”?-Press NO.


:Intheprojectwindow,rightclickonsourceandselectAddnewitem to
group“sourcegroup1”

Select Asmfileandgivenameofthefilewith.s extensionandpressADD.


Typetheprogramintheeditorspaceandsave.

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

mov r0,#34h //lowernibbleofNo.1


mov r1,#12h //highernibbleofNo.1
mov r2,#0dch //lowernibbleofNo.2
mov r3,#0feh //highernibbleofNo.2
clr
c
mov a,r0
add a,r2
mov 22h,a
mov a,r1
add a,r3
c
mov 21h,a
mov 00h,c
end

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.

mova, 21h //do not use#, as dataram21h is


to beaccessedanl a, 22h //logicaland operation
mov30h, a //and operation result stored in
30hmova,21h
orla,22h //logicaloroperation
mov31h, a //oroperationresult
storedin31hmova,21h
xrla,22h //logicalxoroperation
mov32h,a //xoroperationresult
storedin32hend
BeforeExecution:D:21H= 22H=

AfterExecution: D:030H= //ANDoperation


D:031H= //ORoperation
D:032H= //XOR
arethetypeofoperatorsinCthatareusedto perform

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

Addition Add two operands. x y

Subtraction

Subtract the second operand from the first x-y


operand.
Multiplication Multiply two operands.
x y

Division Divide the first operand by the second


operand. x/y

Calculate the remainder when the first


Modulus operand isdivided by the second operand. x y
 C
//Cprogramtodemonstratesyntaxofbinaryarithmetic
//operat
ors
#include
<stdio.h>
intmain()
{
inta=10,b=4,res;
//printingaandb
printf("ais%dandbis%d\n",a,b);
res
=a+b;//additi
on
printf("a+bi
s%d\n",
res);

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:

DecrementOperator Decreasestheintegervalueofthe –horh–


variablebyone.

Increment Operator Increasestheintegervalueofthe ++horh++


variablebyone.

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);

When it is placed after the variable name (also calledpost-incrementoperator), its


valueispreserved temporarily until the execution of this statement and it gets updated
before the execution of the next statement. For example:a = x++;
Itcanbeexpanded toa
= x;
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, .

Whenitisplacedafterthevariablename(alsocalled operator), its


valueis preserved temporarily until the execution of this statementand it gets
updatedbeforetheexecutionofthenextstatement.Forexample, .
CODING OF C IN UNARY OPERATION

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;
}

You might also like