ALP-Embedded Lab

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

1.

Write a ALP to multiply two 16 bit numbers

AREA MULTIPLICATION, CODE, READONLY


EXPORT __main
NUM1 DCD 0x5000
NUM2 DCD 0x4000
__main

LDR R0, NUM1 ; Read the first data


LDR R1, NUM2 ; Read the Second data
MUL R3, R1, R0 ; Multiply R0 with R1 STORE the results in R3
LDR R4,=PRODUCT ; Read the address of Result1 into R4
STR R3,[R4] ; Store the contents of R3 into address point R4
AREA DATA2,DATA,READWRITE
PRODUCT DCD 0X0
END

RESULT:

2. Write a ALP to find the sum of first 10 Integer Numbers


AREA sumofint, CODE, READONLY
EXPORT __main
__main
MOV R0, #10 ;r0=10 Counter for add 10 integers
MOV R1, #00 ;R1 stores sum. initially sum =0
LOOP
ADD R1, R0 ;R1=R1+R0
SUBS R0, #1 ;Decrement R0 BY 1
BNE LOOP ;Branch to label loop, if R0 is not equal to 0
LDR R2,=SUM
STR R1,[R2]
STOP B STOP
AREA SUMINT, DATA, READWRITE
SUM DCD 0x0
END

RESULT:

3. Write a ALP to find the number of 0’s and 1’s in a 32 bit data
AREA count01, CODE, READONLY
EXPORT __main
NUM DCD 0x88000099 ; Initialize the number (1000 1000 0000 0000 0000 0000 1001
1001)
__main
MOV R0,#0 ;R0 is counter for 0
MOV R1,#0 ;R1 is counter for 1
MOV R3,#32 ;R3 indicates 32 bit data
LDR R2, NUM
BACK LSRS R2,#1 ;Logical shift right by 1 time
BCS NEXT ;Branch to Next if carry is
set(LSB=1)
ADD R0,R0,#1 ;R3=R1+1 increment 0's counter
B skip ; Jump or branch to label skip
NEXT ADD R1,R1,#1 ;R3=R1+1 increment 1's counter
skip SUB R3,R3,#1 ;R3=R3-1
CMP R3,#0
BNE BACK ;Branch to Label back if z flag not equal
to 1
END

RESULT:
4. Write ALP to determine whether the given 16 bit number is even or
odd
AREA evenodd, CODE, READONLY
EXPORT __main
NUM DCD 0x00000096 ; Initialize the number
__main
LDR R0, NUM
MOV R2, #0xA
LDR R1, NUM
LSRS R0, #1 ; Logical shift Right by 1 time
BCS NEXT ; Branch to Next if Carry is set[LSB=1]
MOV R2,#0x0 ;If the number is EVEN store 0 in R2
B skip
NEXT MOV R2,#0x1 ;If the number is ODD store 1 in R2
skip NOP

END

RESULT:
5. Write a ALP to write DATA into RAM location
AREA Datawrite, CODE, READONLY
EXPORT __main
DATA DCD 0x12345678
__main
LDR R0,DATA ;LOAD DATA INTO R0
LDR R1,=RAMLOC ;LOAD R1 WITH ADDRESS OF DESTINATION
LOCATION
STR R0,[R1]
LDR R2,=RAMLOC1 ;LOAD R2 WITH ADDRESS OF DESTINATION
LOCATION 1
STR R0,[R2]
LDR R3,=RAMLOC2 ;LOAD R3 WITH ADDRESS OF DESTINATION
LOCATION 2
STR R0,[R3]
AREA RAM , DATA, READWRITE
RAMLOC DCD 0
RAMLOC1 DCD 1
RAMLOC2 DCD 2
END

RESULT:

You might also like