0% found this document useful (0 votes)
85 views23 pages

Kartik Takyar 101803618 Jatin Kapoor 101803619 Himanshu Mahajan 101803620 Gaurish Garg 101803621 Aditi Pandey 101803622

The document contains a practical activity report submitted for an Arm Assembly Language course. It includes 14 programs written in ARM assembly language to perform tasks like addition, subtraction, shifting, checking even/odd numbers, multiplication, division, string operations, and more. The programs demonstrate the use of direct addressing, indirect addressing, barrel shifting and other ARM instructions. Screenshots of the output for each program are provided.

Uploaded by

GAURISH GARG
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)
85 views23 pages

Kartik Takyar 101803618 Jatin Kapoor 101803619 Himanshu Mahajan 101803620 Gaurish Garg 101803621 Aditi Pandey 101803622

The document contains a practical activity report submitted for an Arm Assembly Language course. It includes 14 programs written in ARM assembly language to perform tasks like addition, subtraction, shifting, checking even/odd numbers, multiplication, division, string operations, and more. The programs demonstrate the use of direct addressing, indirect addressing, barrel shifting and other ARM instructions. Screenshots of the output for each program are provided.

Uploaded by

GAURISH GARG
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/ 23

A practical activity report submitted for

Microprocessor Based Systems Design (UCS617)

On

Arm Assembly Language

Submitted by:

Kartik Takyar 101803618


Jatin Kapoor 101803619
Himanshu Mahajan 101803620
Gaurish Garg 101803621
Aditi Pandey 101803622

Submitted to

Dr Rajanpreet Kaur Chahal

Assistant Professor

Computer Science & Engineering Department

Thapar Institute of Engineering & Technology, Patiala-147004

June 14, 2021


Table of Contents
1. Write a program in ARM assembly language to add and subtract two 32-bit numbers using: ................ 3
1.1. Direct Addressing Mode ................................................................................................................................................. 3
1.2. Indirect Addressing Mode .............................................................................................................................................. 4
1.3. Barrel Shifting .................................................................................................................................................................... 5

2. Write a program in ARM assembly language to perform left and right shift of a number ......................... 6

3. Write a program to find whether a number is even or odd. ..................................................................................... 7

4. Write a program to perform multiplication using addition. .................................................................................... 8

5. Write a program to store multiplication table of a number ..................................................................................... 9

6. Write a program to perform division using subtraction......................................................................................... 11

7. Write a program to count the number of characters in a given string ............................................................. 13

8. Write a program to find the number of occurrence of a particular character in a string ........................ 14

9. Write a program to add two integer strings ................................................................................................................. 15

10. Write a program to find the factorial of a number .................................................................................................... 16

11. Write a program to perform 64-bit addition of two 64-bit numbers. .............................................................. 17

12. Write a program to find the largest number in an array. ....................................................................................... 18

13. Write a program to copy an array ..................................................................................................................................... 19

14. Write a program in ARM assembly language to implement the following equations ............................... 20
14.1. ax2+bx2 ................................................................................................................................................................................20
14.2. 6(x+y)+2z+4 ......................................................................................................................................................................21

15. Write a program verify how many bytes are present in a given set which resemble 0xAC ................... 22

16. Write a program to count the number of 1s and 0s ina given byte and verify the result ........................ 23
1. Write a program in ARM assembly language to add and subtract two
32-bit numbers using:

1.1. Direct Addressing Mode


Code:

AREA PROGRAM,CODE,READONLY
ENTRY
MOV R1, #5
MOV R2, #3
ADDS R3, R1, R2
SUBS R4, R1, R2
END

Output:

R3: 0x00000008
R4: 0x00000002

Screenshot:

Figure 1.1

Page 3 of 23
1.2. Indirect Addressing Mode
Code:

AREA PROGRAM, CODE, READONLY


ENTRY
MAIN
LDR R1, =VALUE1
LDR R2, =VALUE2
LDR R3, [R1]
LDR R4, [R2]
ADDS R5, R3, R4
SUBS R6, R3, R4
VALUE1 DCD &00004AFC
VALUE2 DCD &000078AA
END

Output:

R5: 0x0000C3A6
R6: 0xFFFFD252

Screenshot:

Figure 1.2

Page 4 of 23
1.3. Barrel Shifting
Code:

AREA PROGRAM, CODE, READONLY


ENTRY
MAIN
LDR R0,=VALUE1
ADDS R1,R0,R0,LSL #0x01
SUBS R2,R0,R0,LSL #0x01
VALUE1 EQU 4
END

Output:

R1: 0x0000000C
R2: 0xFFFFFFFC

Screenshot:

Figure 1.3

Page 5 of 23
2. Write a program in ARM assembly language to perform left and right
shift of a number
Code:

AREA PROGRAM,CODE,READONLY
ENTRY
LDR R1,VALUE1
MOV R3,R1,LSL#0x01
MOV R4,R1,LSR#0x01
AREA program,data,readonly
VALUE1 DCD &00000004
END

Output:

R3: 0x00000008
R4: 0x00000002

Screenshot:

Figure 2.1

Page 6 of 23
3. Write a program to find whether a number is even or odd.
Code:

AREA PROGRAM,CODE,READONLY
ENTRY
LDR R1, =VALUE1
LDR R2, =VALUE2
AND R3, R1, R2
AREA program,data,readonly
VALUE1 EQU 45
VALUE2 EQU 0x000001
END

Output:

R3: 0x00000001

Screenshot:

Figure 3.1

Page 7 of 23
4. Write a program to perform multiplication using addition.
Code:

AREA PROGRAM,CODE,READONLY
ENTRY
LDR R0, =VALUE1
LDR R1, =VALUE2
MOV R2, R0
MOV R3, #0X01
LOOP
ADD R3,R3,#0X01
ADD R0,R0,R2
CMP R1,R3
BNE LOOP
VALUE1 EQU 2
VALUE2 EQU 6
END

Output:

R0: 0x0000000C

Screenshot:

Figure 4.1

Page 8 of 23
5. Write a program to store multiplication table of a number
Code:

AREA PROGRAM,CODE,READONLY
ENTRY
LDR R0, =VALUE1
LDR R1, =VALUE2
MOV R2, #0X0A
MOV R3,R0
LOOP
STR R0,[R1]
ADD R0, R0, R3
SUB R2, R2, #0X01
ADD R1,R1,#0X04
CMP R2, #0X00
BNE LOOP
VALUE1 EQU 3
VALUE2 EQU 0X00000100
END

Output:

[0x00000100]-[0x0003] = 03
[0x00000104]-[0x0007] = 06
[0x00000108]-[0x000A] = 09 …and so on

Screenshot:

Figure 5.1

Page 9 of 23
Figure 5.2

Page 10 of 23
6. Write a program to perform division using subtraction
Code:

area program,code,readonly
entry
main
LDR R0,dividend
LDR R1,divisor
MOV R2,#0x00
MOV R3,R0
LOOP
SUB R3,R3,R1
ADD R2,R2,#0x01
CMP R3,#0x00
BNE LOOP

area program,data,readonly
dividend DCD &0000000A
divisor DCD &00000002
END

Output:

R2: 0x00000005

Page 11 of 23
Screenshot:

Figure 6.1

Page 12 of 23
7. Write a program to count the number of characters in a given string
Code:

AREA PROGRAM, CODE, READONLY


ENTRY
MAIN
LDR R0, =VALUE1
MOV R2, #0
LOOP
LDRB R1, [R0], #1
CMP R1, #0
ADDNE R2,R2,#1
BNE LOOP
VALUE1 DCB "GAURISH"
END

Output:

R2: 0x00000007

Screenshot:

Figure 7.1

Page 13 of 23
8. Write a program to find the number of occurrence of a particular
character in a string
Code:

AREA PROGRAM, CODE, READONLY


ENTRY
MAIN
LDR R0, =VALUE1 ; POINTER TO VALUE1
MOV R1, #0
LOOP
LDRB R2, [R0], #1
CMP R2,#"G"
ADDEQ R1, R1, #1
CMP R2,#0
BNE LOOP
VALUE1 DCB "GAURISHGARG"
RESULT DCD &00000000
END

Output:

R1: 0x00000003

Screenshot:

Figure 8.1

Page 14 of 23
9. Write a program to add two integer strings
Code:

AREA PROGRAM, CODE, READONLY


ENTRY
MAIN
LDR R1, =VALUE1
LDR R2, =VALUE2
LDR R10, RESULT
MOV R0, #4
LOOP
LDRB R3, [R1], #1
LDRB R4, [R2],#1
ADD R5, R3, R4
STRB R5, [R10], #1
SUB R0, R0, #1
CMP R0,#0
BNE LOOP
VALUE1 DCB 1,2,3,4
VALUE2 DCB 5,6,7,8
RESULT DCD &00000000
END

Output:

[0x00000000-0x00000003] = 06 08 0A 0C

Screenshot:

Figure 9.1

Page 15 of 23
10.Write a program to find the factorial of a number
Code:

AREA PROGRAM, CODE, READONLY


ENTRY
MAIN
LDR R1, =VALUE1
MOV R2, #1
MOV R3, #1
LOOP
ADD R3, #1
MUL R4, R2,R3
MOV R2, R4
CMP R3,R1
BNE LOOP
VALUE1 EQU 5
END

Output:

R2: 0x00000078

Screenshot:

Figure 10.1

Page 16 of 23
11.Write a program to perform 64-bit addition of two 64-bit numbers.
Code:

AREA PROGRAM, CODE, READONLY


ENTRY
MAIN
LDR R0, =VALUE1 ;POINTER TO VALUE1
LDR R1,[R0] ;FIRST 32 BITS (MSB)
LDR R2, [R0,#4] ;OFFSET R2 BY 4 BYTES AND STORE LSB
LDR R3, =VALUE2 ; POINTER TO VALUE2
LDR R4, [R3]; FIRST 32 BITS OF VALUE2
LDR R5, [R3, #4] ;;OFFSET R2 BY 4 BYTES AND STORE LSB
ADDS R6, R2, R5
ADC R7, R1, R4
LDR R8, RESULT ;ADDRESS WHERE THE ANSWER IS STORED
STR R7, [R8] ;STORE R7 MSB IN ADDRESS SPECIFIED BY R8
STR R6, [R8,#4] ;OFFSET BY 4 BYTES
VALUE1 DCD &124A93FE,&7B4AD3F2
VALUE2 DCD &82129CFF,&14FCBA41
RESULT DCD &00000000
END

Output:

[0x0000000 – 0x00000007] = 94 5D 30 FD 90 47 8E 33

Screenshot:

Figure 11.1

Page 17 of 23
12.Write a program to find the largest number in an array.
Code:

AREA PROGRAM, CODE, READONLY


ENTRY
MAIN
LDR R0, =VALUE1
LDRB R1, [R0] ;need to bytewise load it
MOV R2, #10
LOOP
LDRB R3, [R0], #1
CMP R3,R1
MOVGT R1, R3 ;OUTPUT WILL BE STORED IN R1
SUB R2, R2, #1
CMP R2,#0
BNE LOOP
VALUE1 DCB 9,8,0,3,0,0,2,5,5,1 ;it's an array
END

Output:

R1: 0x000000009

Screenshot:

Figure 12.1

Page 18 of 23
13.Write a program to copy an array
Code:

AREA PROGRAM, CODE, READONLY


ENTRY
MAIN
LDR R0, =VALUE1 ;pointer to array
LDR R2, RESULT
MOV R3,#10
LOOP
LDRB R1, [R0], #1
STRB R1, [R2], #1
SUB R3, R3, #1
CMP R3,#0
BNE LOOP
VALUE1 DCB 9,8,0,3,0,0,2,5,5,1
RESULT DCD &00000000
END

Output:

[0x00000000-0x000000009] = 09 08 00 03 00 00 02 05 05 01

Screenshot:

Figure 13.1

Page 19 of 23
14.Write a program in ARM assembly language to implement the following
equations

14.1. ax2+bx2
Code:

AREA PROGRAM, CODE, READONLY


ENTRY
MAIN
LDR R1, =a
LDR R2, =k
LDR R3, =b
LDR R4, =y
MUL R5,R2,R2
MUL R6, R1,R5
MUL R7,R4,R4
MUL R8, R3,R7
ADD R9, R6,R8
a EQU 1
k EQU 2
b EQU 3
y EQU 4
END

Output:

R9: 0x00000034

Screenshot:

Figure 14.1
Page 20 of 23
14.2. 6(x+y)+2z+4
Code:

AREA PROGRAM, CODE, READONLY


ENTRY
MAIN
LDR R1, =x
LDR R2, =y
LDR R3, =z
ADD R4, R1,R2
MOV R10, #6
MUL R5, R4, R10
MOV R10, #2
MUL R6, R3,R10
MOV R7,#4
ADD R8, R5,R6
ADD R9, R8, R7
x EQU 1
y EQU 2
z EQU 3
END

Output:

R9: 0x0000001C

Screenshot:

Figure 14.2

Page 21 of 23
15.Write a program verify how many bytes are present in a given set which
resemble 0xAC
Code:

AREA PROGRAM,CODE,READONLY
ENTRY
LDR R0,value ; address
MOV R3,#0x0A ; counter 32 bit
LOOP
LDRB R1,[R0],#0x01
CMP R1,#0xAC
ADDEQ R2,R2,#1
SUBS R3,R3,#1
BNE LOOP
AREA PROGRAM,DATA,READONLY
value DCD &0000000E
END

Output:

R2: 0x00000001

Screenshot:

Figure 15.1

Page 22 of 23
16.Write a program to count the number of 1s and 0s ina given byte and
verify the result
Code:

AREA PROGRAM,CODE,READONLY
ENTER
LDR R0,VALUE0
MOV R1,#0X004
MOV R2,#0X00 ;NUMBER 0F 1S
MOV R3,#0X00 ;NUMBER OF 0S
loop
MOVS R0,R0,RRX ;ROTATE RIGHT WITH EXTEND
ADDCC R2,#0X001 ;0S
ADDCS R3,#0X001 ;1S
SUBS R1,R1,#0X001 ;COUNTER
CMP R1,#0X00
BNE loop
AREA PRODRAM,DATA,READONLY
VALUE0 DCD &00000008
END

Output:

R3: 0x00000001

Screenshot:

Figure 16.1

Page 23 of 23

You might also like