KEMBAR78
Microcontroller Lab Software MANUAL | PDF | Embedded System | Microcontroller
0% found this document useful (0 votes)
192 views17 pages

Microcontroller Lab Software MANUAL

The document describes several assembly language programs (ALPs) that perform various calculations: 1) Multiply two 16-bit numbers and store the result in a register. 2) Find the sum of the first 10 integers and store the result in a register. 3) Find the factorial of a number and store the result in a register. 4) Add an array of 16-bit numbers and store the 32-bit result in internal RAM.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
192 views17 pages

Microcontroller Lab Software MANUAL

The document describes several assembly language programs (ALPs) that perform various calculations: 1) Multiply two 16-bit numbers and store the result in a register. 2) Find the sum of the first 10 integers and store the result in a register. 3) Find the factorial of a number and store the result in a register. 4) Add an array of 16-bit numbers and store the 32-bit result in internal RAM.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Microcontroller and Embedded Systems Lab

PART A
SOFTWARE PROGRAMS

1. Write an ALP to multiply two 16 bit binary numbers.


Area multiply, code, read-only
entry ;Mark first instruction to execute
start
mov r1,#6400 ;Store First number in R1
mov r2,#3200 ;Store Second number in R2
mul r3,r1,r2 ;Multiplication
nop
nop
nop
end;Mark end of file
Output: The result of multiplication is stored in register R3

DEPT of CSE, RYMEC , BALLARI Page 1


Microcontroller and Embedded Systems Lab

2. Write an ALP to find the sum of first 10 integer numbers.


area summation,code,readonly
entry ;Mark first instruction to execute
start mov r5,#10 ;Initialize counter to 10(i.e.N=10)
mov r0,#0 ;Initialize Sum to zero
mov r1,#1
loop add r0,r0,r1 ;Add the elements
add r1,r1,#1
subs r5,r5,#1 ;Decrement counter
cmp r5,#0
bne loop
ldr r4,=result
str r0,[r4]
xss b xss
area data2,data,readwrite
result dcd 0x0
end
Output: The Sum of First 10 integers is stored in register R0

DEPT of CSE, RYMEC , BALLARI Page 2


Microcontroller and Embedded Systems Lab

3. Write an ALP find to find factorial of a number.


area factorial,code,readonly
entry ;Mark first instruction to execute
start
mov r0,#7 ;Store a factorial number in R0
mov r1,r0 ;Move the same number in R1
fact subs r1,r1,#1 ;Subtraction
cmp r1,#1 ;Comparison
beq stop
mul r3,r0,r1 ;Multiplication
mov r0,r3 ;Result
bne fact
stop nop
nop
nop
end ;Mark end of file
Output: The Factorial is stored in register R0

DEPT of CSE, RYMEC , BALLARI Page 3


Microcontroller and Embedded Systems Lab

4. Write an ALP to add an array of 16 bit numbers and store the 32 bit result
in internal RAM
area addition,code,readonly
entry ;Mark first instruction to execute
start
mov r5,#3 ;Initialize Counter to 3(i.e. N=3)
mov r0,#0 ;Initialize Sum to Zero
ldr r1,=value1
loop ldr r2,[r1],#2 ;Word align to array element
ldr r3,mask
AND r2,r2,r3
add r0,r0,r2
subs r5,r5,#1
cmp r5,#0
bne loop
ldr r4,=result
str r0,[r4]
xss b xss
mask dcd 0x0000ffff
value1 dcw 0x1111,0x2222,0x4444 ;Array of 16 bit
;Numbers(N=3)
area data2,data,readwrite
result dcd 0x0
end

DEPT of CSE, RYMEC , BALLARI Page 4


Microcontroller and Embedded Systems Lab

Output: The result is stored in memory location Result (R0).

DEPT of CSE, RYMEC , BALLARI Page 5


Microcontroller and Embedded Systems Lab

5. Write an ALP to find the square of a numbers (1 to 10)using look-up table.


area square,code,readonly
entry ;Mark first instruction to execute
start
ldr r0,=table1 ;Load start address of look up table
ldr r1,=7 ;Load no whose square is to find
mov r1,r1,lsl#0x2 ;Generate address corresponding to square ofgiven no
add r0,r0,r1 ;Load addr of element in lookup table
ldr r3,[r0] ;Get square of given no in R3
xss b xss
table1DCD 0X00000000 ;Table holds Sqr of 1-10 in Hex decimal
DCD 0X00000001
DCD 0X00000004
DCD 0X00000009
DCD 0X00000010
DCD 0X00000019
DCD 0X00000024
DCD 0X00000031
DCD 0X00000040
DCD 0X00000051
DCD 0X00000064;
area data1,data,readwrite
result DCD 0X00000000
end

Output: The Result is stored in memory location R3

DEPT of CSE, RYMEC , BALLARI Page 6


Microcontroller and Embedded Systems Lab

DEPT of CSE, RYMEC , BALLARI Page 7


Microcontroller and Embedded Systems Lab

6a. Write an ALP to find the largest number in an array of 32 numbers.


area largest,code,readonly
entry ;Mark first instruction to execute

start mov r5,#6 ;Initialize counter to 6(i.e. N=7)


ldr r1,=value1 ;Loads the address of first value
ldr r2,[r1],#4 ;Word align to array element
loop ldr r4,[r1],#4 ;Word align to array element
cmp r2,r4 ;Compare numbers
bhi loop1
mov r2,r4
loop1 subs r5,r5,#1
cmp r5,#0
bne loop
ldr r4,=result
str r2,[r4]
XSS B XSS
value1 DCD 0X44444444
DCD 0X22222222
DCD 0X11111111
DCD 0X33333333
DCD 0XAAAAAAAA
DCD 0X88888888
DCD 0X99999999
area data1,data,readwrite
result DCD 0X00000000
end

DEPT of CSE, RYMEC , BALLARI Page 8


Microcontroller and Embedded Systems Lab

DEPT of CSE, RYMEC , BALLARI Page 9


Microcontroller and Embedded Systems Lab

6b. Write an ALP to find thesmallest number in an array of 32 numbers.

area smallest,code,readonly
entry ;Mark first instruction to execute
start mov r5,#6 ;Initialize counter to 6(i.e. N=7)
ldr r6,=result
ldr r1,=value1 ;Loads the address of first value
ldr r2,[r1],#4 ;Word align to array element
loop ldr r4,[r1],#4 ;Word align to array element
cmp r2,r4 ;Compare numbers
bls loop1
mov r2,r4
loop1 subs r5,r5,#1
cmp r5,#0
bne loop
ldr r4,=result
str r2,[r4]
xss b xss
value1 DCD 0X44444444
DCD 0X22222222
DCD 0X33333333
DCD 0x11111111
DCD 0xAAAAAAAA
DCD 0X88888888
DCD 0X99999999
area data1,data,readwrite
result DCD 0X00000000
end

Output: The result is stored in memory location Result

DEPT of CSE, RYMEC , BALLARI Page 10


Microcontroller and Embedded Systems Lab

DEPT of CSE, RYMEC , BALLARI Page 11


Microcontroller and Embedded Systems Lab

7a. write an alp to arrange a series of 32 bit numbers in ascending order.


area ascending, code, readonly
entry ;Mark first instruction to execute

start mov r8,#4 ;Initialize counter to 4(i.e. N=4)


ldr r2,=cvalue
ldr r3,=dvalue ;Address of data region loop0
loop0 ldr r1,[r2],#4
str r1,[r3],#4 ;Loading values from code region
subs r8,r8,#1
cmp r8,#0
bne loop0
start1 mov r5,#3
mov r7,#0
ldr r1,=dvalue
loop ldr r2,[r1],#4
ldr r3,[r1]
cmp r2,r3
blt loop2
str r2,[r1],#-4
str r3,[r1]
mov r7,#1
add r1,#4
loop2 subs r5,r5,#1
cmp r5,#0
bne loop
cmp r7,#0
bne start1
xss b xss
cvalue DCD 0X44444444
DCD 0X11111111
DCD 0X33333333
DCD 0X22222222

area data1,data,readwrite
dvalue DCD 0x00000000
end

DEPT of CSE, RYMEC , BALLARI Page 12


Microcontroller and Embedded Systems Lab

7b. write an alp to arrange a series of 32 bit numbers in ascending order.

area ascending,code,readonly ;Mark first instruction to execute


entry
start mov r8,#4 ;Initialize counter to 4(i.e. N=4)
ldr r2,=cvalue
ldr r3,=dvalue ;Address of data region loop0
loop0 ldr r1,[r2],#4 ;Loading values from code region
str r1,[r3],#4
subs r8,r8,#1
cmp r8,#0
bne loop0
start1 mov r5,#3

DEPT of CSE, RYMEC , BALLARI Page 13


Microcontroller and Embedded Systems Lab

mov r7,#0
ldr r1,=dvalue
loop ldr r2,[r1],#4
ldr r3,[r1]
cmp r2,r3
bgt loop2
str r2,[r1],#-4
str r3,[r1]
mov r7,#1
add r1,#4
loop2 subs r5,r5,#1
cmp r5,#0
bne loop
cmp r7,#0
bne start1
xss b xss
cvalue DCD 0X44444444
DCD 0X11111111
DCD 0X33333333
DCD 0X22222222
area data1,data,readwrite
dvalue DCD 0x00000000
end

DEPT of CSE, RYMEC , BALLARI Page 14


Microcontroller and Embedded Systems Lab

DEPT of CSE, RYMEC , BALLARI Page 15


Microcontroller and Embedded Systems Lab

8. Write an ALP to count the number of ones and zeroes in two


consecutive memory locations.

areaonezero,code,readonly
entry ; Mark first instruction to execute
start
mov r2,#0 ;Counter for Ones
mov r3,#0 ;Counter for Zeroes
mov r7,#2 ;Counter to get two words
ldr r6,=value ;loads the address of value
loop mov r1,#32 ;32 bits counter
ldr r0,[r6],#4 ; Get the 32 bit value
loop0 movs r0,r0,ror#1 ;Right shift to check carry
bhi ones
zerosadd r3,r3,#1 ;If carry bit 0 then incr the cntr by 1(R3) b
loop1 ;Branch to loop1
ones add r2,r2,#1
loop1 subs r1,r1,#1
bne loop0
subs r7,r7,#1
cmp r7,#0
bne loop
xss b xss
value dcd 0x3,0x2 ;Both values are of 32 bit each
end

Output: The number of ones stores in R2 and number of zeroes are stored
in R3

DEPT of CSE, RYMEC , BALLARI Page 16


Microcontroller and Embedded Systems Lab

DEPT of CSE, RYMEC , BALLARI Page 17

You might also like