0% found this document useful (0 votes)
86 views6 pages

Assembly Language Programs Collection

1) The document contains 7 ARM assembly language programs (ALPs) that perform various tasks: multiplication of 16-bit binary numbers, addition of the first 10 integers, calculating a factorial, adding an array of 16-bit numbers and storing the 32-bit result, finding the square of a number using a lookup table, finding the largest number in an array, and arranging numbers in ascending order using a bubble sort algorithm. 2) The ALPs use common ARM instructions like LDR, STR, ADD, SUB, MUL, CMP, BCC, and SWI. They demonstrate accessing memory locations, loading values, performing arithmetic operations, conditional branching, and stopping program execution. 3) The

Uploaded by

M.A raja
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)
86 views6 pages

Assembly Language Programs Collection

1) The document contains 7 ARM assembly language programs (ALPs) that perform various tasks: multiplication of 16-bit binary numbers, addition of the first 10 integers, calculating a factorial, adding an array of 16-bit numbers and storing the 32-bit result, finding the square of a number using a lookup table, finding the largest number in an array, and arranging numbers in ascending order using a bubble sort algorithm. 2) The ALPs use common ARM instructions like LDR, STR, ADD, SUB, MUL, CMP, BCC, and SWI. They demonstrate accessing memory locations, loading values, performing arithmetic operations, conditional branching, and stopping program execution. 3) The

Uploaded by

M.A raja
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/ 6

1)Write an ALP to multiply two 16 bit binary

numbers.
;Multiplication of Two 16 Bit binary numbers
;TTL 16bitBMUL

AREA Program, CODE, READONLY


ENTRY

LDR R0, MEMORY ; load Address of memory


LDRH R1, [R0] ; load First number
LDRH R2, [R0,#2]; load Second number
MUL R2, R1, R2 ;
R0 = R1 x R0
STRH R2, [R0,#4] ; Store the result
SWI &11 ; all done

MEMORY DCD 0x40000000 ;Address of First 16 bit number

END

2) Write a program to find the sum of first 10


integer numbers.
AREA PROGRAM, CODE, READONLY

ENTRY

LDR R0, MEM

MOV R4, #9

LDRB R1, [R0]

UP LDRB R2, [R0, #1]

ADD R3, R1, R2

MOV R1, R3

ADD R0, R0, #1

SUB R4, R4, #1

CMP R4,#0

BNE UP

STRB R3,[R0,#2]
SWI &11

MEM DCD 0x40000000

END

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


;TTL factorial
AREA Program, CODE, READONLY
ENTRY
LDR R0,LOOKUP
LDRB R1,[R0]
MOV R2,R1 ; Copy the offset value
UP ADD R1,R1,#-1; decrement offset value
CMP R1,#0 ; is offset value is zero
BEQ STORE ; if yes store factorial value
MUL R3,R2,R1; if not fact= offsetvalue x (offset-1)
MOV R2,R3 ; move fact value
B UP; branch to decrement offset value
STORE STR R2,[R0,#4] ; store the fact value
SWI &11; Stop

LOOKUP DCD 0X40000000 ; Address of the memory where


offset value is loaded.

END
4)Write an ALP to add an array of 16 bit
numbers and store the 32 bit result in internal
RAM
;PROGRAM TO ADD ARRAY OF 16 BIT NUMBERS AND STORE THE 32 BIT RESULT
IN MEMORY
;TTL 16bitADD
AREA Program, CODE, READONLY
ENTRY

LDR R0, MEMORY ; load Address of memory


LDRB R1, [R0] ; load array number
ADD R0,R0,#2
LDRH R2,[R0] ; load First number
ADD R1,#-1
UP ADD R0,R0,#2
LDRH R3,[R0] ; load next 16 bit number
ADD R2, R3, R2 ; R2 = R3 + R2
ADD R1,#-1
CMP R1,#0 ; is count is zero
BNE UP ; is yes store the sum,else load next number
STRH R2,[R0,#2] ; Store the sum
Here B Here ; end of program

MEMORY DCD 0x40000000

END

5)Write an ALP to find the square of a number


(1 to 10) using look-up table
;TTL Square of a number 1 TO 9
AREA Program, CODE, READONLY
ENTRY

LDR R0,LOOKUP ; load the address of the


lookup table
LDR R2,RESULT; load the address of the RESULT
LDRB R1,[R0]; offset of value to be SQUARED
ADD R0,R0,R1; points to memory where square
of the given number is stored
LDRB R3,[R0]; load the squared value
STRB R3,[R2]; store the squared value
HERE B HERE
LOOKUP DCD 0X40000000 ; address of the offset value
RESULT DCD 0X40000018 ; address of the result
END

6) Write an ALP to find the largest/smallest


number in an array of 32 numbers
;TTL Largest_16bit
AREA Program, CODE, READONLY
ENTRY

MOV R0, #0X40000000 ; load the address of


the lookup table
LDRH R1, [R0]
MOV R2,#0X00000003 ; load the count
Loop CMP R2, #0 ; is the count is
zero
BEQ Done ; yes store largest
ADD R0, R0, #2 ; increment pointer
LDRSH R3, [R0] ; else get next the data
CMP R3, R1 ; bit is 1
BGE Looptest ; skip next line if zero
MOV R1, R3 ; increment -ve number count
Looptest
SUBS R2, R2, #0x1; decrement count with zero set
BNE Loop ; if zero flag is not set, loop
Done
MOV R4,#0X40000015 ;store largest
STR R1,[R4]
SWI &11

END

7)Write an ALP to arrange a series of 32 bit


numbers in ascending/descending order.
;TTL Bobble sort ,assending order
AREA Program, CODE, READONLY
ENTRY
MOV R6,#0X40000000; pointer to start of list
LDRB R0, [R6] ; get the length of list

UP ADD R6, R6,#01 ; make a copy of start of list


ADD R8,R0,#-1
MOV R7, R6

Next
LDRB R2, [R7] ; load the first byte
ADD R8,R8,#-1
LDRB R3, [R7,#1] ; load the second byte
CMP R2, R3 ; compare them
BCC NoSwitch ; branch if r2 less than r3
STRB R2, [R7,#1] ; otherwise swap the bytes
STRB R3, [R7] ; like this
NoSwitch
ADD R7,#1 ; points to next dat location
CMP R8,#0 ; is innner count is zero
BHI Next ; if no goto get next higher value
ADD R0,R0,#-1 ; decrement the data count
CMP R0, #0 ; if all data are sorted,yes stop
otherwise sort again
MOV R6,#0X40000000 ; load starting address
BNE UP ; if so check again - outer loop

Done SWI &11 ; all done

8)Write an ALP to count the number of ones and


zeros in two consecutive memory locations.
; TTL count the number of ones and zeros in two consecutive memory
locations
AREA Program, CODE, READONLY
ENTRY

LDR R0,LOOKUP ; load the address of the


lookup table
LDR R1,[R0] ; load 32 bit number
mov r4,#32 ; load rotation count

ROTATE RORS R1,#1 ; rotate right by one bit,


update cpsr
BCS ONES ; is carry is = 1
ADD R3,R3,#1 ; no increment zero's counter
B NEXT ; branch to next rotation
ONES ADD R2,R2,#1 ; yes increment one's counter
NEXT ADD R4,R4,#-1 ; Decrement the rotation count
CMP R4,#0 ; is rotation count is zero
BNE ROTATE ; no,go to rotate
STORE ADD R0,R0,#04 ; load address of memory for
no of one's
STRB R3,[R0] ; store no of one's
ADD R0,R0,#1 ; load address of memory for no
of zero's
STRB R2,[R0] ; store no of zero's
SWI &11
LOOKUP DCD 0X40000000 ; memory address of
lookup table

END

You might also like