ARM Assembly Language Programming Exercises, Assignments of Computer Science

this is practice qui on pipelining in computer organization. here some usefull formula and concept

Typology: Assignments

2019/2020

Uploaded on 10/29/2020

modi-ketul-1
modi-ketul-1 🇮🇳

4.7

(3)

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Assembly Language Concepts using ARM
Q. 1 | Convert the following C program to ARM assembly. Store the integer, i , in register r 0.
Assume that the starting address of array a is saved in register r 1, and the starting address of
array b is saved in register r 2.
int i;
int b[500];
int a[500];
for(i=0; i < 500; i++) {
b[i] = a[a[i]];
}
Q. 2 | Write an ARM assembly instruction code to count the number of
1's in a 32 bit number.
Soln: l0:
and r1, r0, r3
mov r0, r0, lsl #1
cmp r1, #0
addne r4, r4, #1
cmp r0, #0
bne l0
mov pc, lr
count:
mov r4, #0
mov r0, #1
bl l0
Q. 3 | Design a ARM language program that examines a 32-bit value stored in r1 and counts the
number of contiguous sequences of 1s. For example, the value:
01110001000111101100011100011111
Soln :
l0:
cmp r4, #0
moveq r4, #1
addeq r2, r2, #1
mov pc, lr
l1:
and r3, r1, r0
cmp r3, #0
stmfd sp!, {lr}
pf2

Partial preview of the text

Download ARM Assembly Language Programming Exercises and more Assignments Computer Science in PDF only on Docsity!

Assembly Language Concepts using ARM

Q. 1 | Convert the following C program to ARM assembly. Store the integer, i , in register r 0.

Assume that the starting address of array a is saved in register r 1, and the starting address of array b is saved in register r 2. int i; int b[500]; int a[500]; for(i=0; i < 500; i++) { b[i] = a[a[i]]; }

Q. 2 | Write an ARM assembly instruction code to count the number of

1's in a 32 bit number. Soln: l0: and r1, r0, r mov r0, r0, lsl # cmp r1, # addne r4, r4, # cmp r0, # bne l mov pc, lr count: mov r4, # mov r0, # bl l

Q. 3 | Design a ARM language program that examines a 32-bit value stored in r1 and counts the

number of contiguous sequences of 1s. For example, the value:

Soln :

l0: cmp r4, # moveq r4, # addeq r2, r2, # mov pc, lr l1: and r3, r1, r cmp r3, # stmfd sp!, {lr}

blne l ldmfd sp!, {lr} cmp r3, # moveq r4, # mov r0, r0, lsl # cmp r0, # bne l mov pc, lr count: mov r2, # mov r0, # mov r4, # bl l

Q. 4 | Write an ARM assembly program to nd out if a number is prime

using a recursive algorithm. l1: mod r5, r3, r cmp r5, # addeq r2, r2, # add r4, r4, # cmp r4, r ble l mov pc, lr prime: mov r7, # mov r3, r mov r6, r0, lsr # mov r4, # mov r2, # bl l cmp r2, # moveq r7, #

Q. 6 | Write an ARM assembly program to add two 96-bit numbers A and B using the minimum

number of instructions. A is stored in three registers r2, r3 and r4 with the MSB in r2 and LSB in r4. B is stored in registers r5, r6 and r7 with the MSB in r5 and LSB in r7. Place the nal result in r8(MSB), r9 and r10(LSB).