Professional Documents
Culture Documents
As
AREA Program, CODE, READONLY
ENTRY
EXPORT __main
__main
MOV R1, #0x40000000 ;Initialize the memory location
LDRH R0, [R1] ;Get the first 16-bit number
LDRH R2, [R1,#2] ;Get the second 16-bit number
MUL R0, R2 ;Multiply the two 16-bit numbers
STR R0, [R1,#6] ;Store the multiplied number to memory location
SWI &11
END
2. Write an ALP to find the sum of first ten integer numbers.
__main
MOV R0, #0x40000000 ; Load the starting memory address
EOR R1, R1, R1 ; Clear R1 register
MOV R2, #0xA ; Initialize the counter
Loop
LDRH R3,[R0] ; Get the first integer to R3 register
ADD R1,R1,R3 ; Add the cotent of R1 & R3 and store the sum in R1
ADD R0,R0,#+2 ; Update the memory location to next integer
SUBS R2,R2,#0x1 ; Decrement the counter
BNE Loop ; If counter is not zero go back to add next integer
STR R1,[R0,#4] ; If counter is zero store the sum in the memory location
SWI &11
END
3. Write an ALP to find the number of 1’s and 0’s in a given 32-bit data.
AREA Program, CODE, READONLY
ENTRY
EXPORT __main
__main
MOV R0, #0x40000000 ;Initialize the memory location
EOR R2, R2, R2 ;Clear R2 register to count the number of one's
EOR R3, R3, R3 ;Clear R3 register to count the number of zero's
MOV R1, #32 ;Initialize the counter the number of bits in the data (32-bits)
LDR R4, [R0] ;Get the 32-bit data to register
Loop
MOVS R4, R4, ROR #1 ;Rotate right through carry and update it in the same register
BCS Loop1 ;If carry is set go to increase number of one's
ADD R3,R3,#0x1 ;If carry is reset increase number of zero's
B Eloop ;Go to check if the counter is zero
Loop1
ADD R2,R2,#0x1 ;Increment the number of one's
Eloop
SUB R1,#0x1 ;Decrement the counter
CMP R1,#00 ;Compare if the counter is zero
BNE Loop ;If zero continue with next instruction else go
back to check the next bit
SWI &11
END
Alternate Program:
AREA Program, CODE, READONLY
ENTRY
EXPORT __main
__main
MOV R0, #0x40000000
MOV R1, #32
LDR R4, [R0]
Loop
MOVS R4, R4, ROR #1
ADDCS R3,R3,#0x1
ADDCC R2,R2,#0x1
SUB R1,#0x1
CMP R1,#00
BNE Loop
SWI &11
END
4. Write an ALP to find the given 16-bit number is odd or even.
__main
MOV R0, #0x40000000 ;Initialize the memory
LDRH R4, [R0] ;Get the data to be checked for odd or even
Loop
AND R4,#0x1 ;Logically AND with 1
CMP R4,#00 ;Compare the result with 00
BNE loop1 ;If the result is zero update R1 with 1 else update
with 0
ADD R1,#0x0 ;Add R1 with zero to say the number is even
B Eloop ;Go to exit
loop1
ADD R1,#0x1 ;Add R1 with one to say the number is odd
Eloop
STR R1,[R0,#4] ;Store the number in memory location
SWI &11
END
5. Write an ALP to write data to RAM memory