1. a) Write an ALP to add, subtract, multiply, divide two 16-bit binary numbers.
AREA NAME, DATA, READONLY
EXPORT Vectors
Vectors
DCD 0X00000000
DCD Reset_Handler
AREA CC,CODE,READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler
MOV R1,#0X1A34
MOV R2,#0X1696
ADD/MUL/SUB/UDIV R0,R1,R2
END
1. b) Write an ALP to find the sum of first 10 integer numbers.
AREA SUM, DATA, READONLY
EXPORT Vectors
Vectors
DCD 0X00000000
DCD Reset_Handler
AREA CC,CODE,READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler
MOV R0,#0X0000
MOV R1,#0X0000
MOV R2,#0X000A
Sum
ADD R1,R1,R0
ADD R0,R0,#0X0001
CMP R0,R2
BNE Sum
END
1. c) Write an ALP to find factorial of a number
AREA FACTORIAL, DATA, READONLY
EXPORT Vectors
Vectors
DCD 0x20001000
DCD Reset_Handler
AREA CC, CODE, READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler
MOV R0, #5
MOV R1, #1
MOV R2, #1
Factorial_Loop
MUL R1, R1, R0
SUB R0, R0, #1
CMP R0, R2
BNE Factorial_Loop
END
1. d) Write an ALP to add an array of 16-bit numbers and store the 32-bit result in internal RAM
AREA RESET, DATA, READONLY
EXPORT Vectors
Vectors
DCD 0x20001000
DCD Reset_Handler
AREA CC, CODE, READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler
MOV R0,0X20000000
MOV R3,#0005
MOV R4,#0002
LDRH R1,[R0]
Label
LDRH R2,[R0,R4]
ADD R1,R1,R2
ADD R0,R0,#002
SUBS R3,R3,#0001
BNE Label
STR R1,[R0,R4]
END
3. a) Write an ALP to find the largest/smallest number in an array of 32 numbers
AREA RESET, DATA, READONLY
EXPORT Vectors
Vectors
DCD 0x20001000
DCD Reset_Handler
AREA CC, CODE, READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler
MOV R0,#0X20000000
MOV R3,#0X0005
MOV R4,#0X0004
LDR R1,[R0]
Label LDR R2,[R0,R4]
CMP R1,R2
BGT/BLT L1 ; BGT FOR LARGEST & BLT FOR SMALLEST
MOV R1,R2
L1 ADD R0,R0,#0004
SUBS R3,R3,#0001
BNE Label
STR R1,[R0,R4]
END
3. b) Write an ALP to arrange a series of 32-bit numbers in ascending/descending order
AREA RESET, DATA, READONLY
EXPORT Vectors
Vectors
DCD 0x20001000
DCD Reset_Handler
AREA CC, CODE, READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler
MOV R4,#0004
MOV R6,#0005
Label2 MOV R5,R6
MOV R0,#0x20000000
Label LDR R1,[R0]
LDR R2,[R0,R4]
CMP R1,R2
BLT/BGT L1 ;BLTFOR ASCENDING & BGTFOR DESCENDING
STR R1,[R0,R4]
STR R2,[R0]
L1 ADD R0,R0,#0004
SUBS R5,R5,#0001
BNE Label
SUBS R6,R6,#0001
CMP R6,#0000
BNE Label2
END
4) Write an ALP to count the number of ones and zeros in two consecutive memory locations.
AREA RESET, DATA, READONLY
EXPORT Vectors
Vectors
DCD 0x20001000
DCD Reset_Handler
AREA CC, CODE, READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler
MOV R4,#0X20000000
LDR R0,[R4]
MOV R1,#0X0020
MOV R4,#0X0020
MOV R2,#0X0000
Label RRXS R0
BCC L1
ADD R2,R2,#0001
L1 SUBS R1,R1,#0001
BNE Label
SUB R3,R4,R2
END
(OR)
AREA FACTORIAL, DATA, READONLY
EXPORT Vectors
Vectors
DCD 0x20001000
DCD Reset_Handler
AREA CC, CODE, READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler
MOV R1,#0x0020
MOV R4,#0X0020
MOV R2,#0x0000
LDR R0,=0x1011010
Label RRXS R0
BCC L1
ADD R2,R2,#0001
L1 SUBS R1,R1,#0001
BNE Label
SUB R3,R4,R2
END
5. Write an ALP to Scan a series of 32-bit numbers to find how many are negative.
AREA RESET, DATA, READONLY
EXPORT Vectors
Vectors
DCD 0x20001000
DCD Reset_Handler
Data DCD -100,20,6,-5,-99
AREA CC, CODE, READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler
LDR R0,=Data
MOV R2,#0005
L2 LDR R1,[R0]
LSLS R1,R1,#0001
BCC L1
ADD R3,#0001
L1 ADD R0,R0,#0004
SUB R2,#0001
CMP R2,#0000
BNE L2
END
6. Write an ALP to Scan a series of 32-bit numbers to find how many are positive.
AREA RESET, DATA, READONLY
EXPORT Vectors
Vectors
DCD 0x20001000
DCD Reset_Handler
Data DCD -100,20,6,-5,-99
AREA CC, CODE, READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler
LDR R0,=Data
MOV R2,#0005
L2 LDR R1,[R0]
LSLS R1,R1,#0001
BCC L1
ADD R3,#0001
L1 ADD R0,R0,#0004
SUB R2,#0001
CMP R2,#0000
BNE L2
SUB R5,R2,R3
END
R5 LO POSITIVE NO. UNTAI