100% found this document useful (1 vote)
966 views

ARM Processor Programs

The document describes 9 programming aims for an ARM processor. It provides the assembly code to add two words and store the result, add two 64-bit numbers, calculate the 2's complement of a number, disassemble a byte into nibbles, find the number of 1's in a binary number, find the lowest number in a series, add two packed BCD numbers to give a packed BCD result, divide two numbers using repeated subtraction, and calculate the factorial of a number. For each aim, it lists the assembly code and expected output.

Uploaded by

monsan_83
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
966 views

ARM Processor Programs

The document describes 9 programming aims for an ARM processor. It provides the assembly code to add two words and store the result, add two 64-bit numbers, calculate the 2's complement of a number, disassemble a byte into nibbles, find the number of 1's in a binary number, find the lowest number in a series, add two packed BCD numbers to give a packed BCD result, divide two numbers using repeated subtraction, and calculate the factorial of a number. For each aim, it lists the assembly code and expected output.

Uploaded by

monsan_83
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

ARM Processor Programming

Jaspreet Kaleka
Thapar University, Patiala
ME-EC-2010
801061009
Lab Advisor
Dr. Sanjay Sharma
Associate Professor
ECED
Thapar University, Patiala, India
ARM Processor Programming 2011

Aim 1: Add two WORDs & store the result in memory.

AREA MY_PROGRAM, CODE


ENTRY

MOV R2, #2 ; First Number


MOV R3, #3 ; Second Number

ADD R1, R2, R3 ; R1 = R2 + R3

LDR R4, =DEST ; R4 = pointer to DEST.


STR R1, [R4] ;Store R1 at DEST.

AREA MY_PROGRAM_Data, DATA

DEST DCD 0

END

Output:

Page | 1
ARM Processor Programming 2011

Aim 2: Add two 64-bit numbers.

AREA MY_PROGRAM, CODE

ENTRY

LDR R1, =&ABCDEFAB ; First number (63-32)


LDR R2, =&00000001 ; First number (31-0)
LDR R3, =&00000001 ; Second number (63-32)
LDR R4, =&00000001 ; Second number (31-0)

ADDS R3, R3, R1


ADC R4, R4, R2

END

Output:

Page | 2
ARM Processor Programming 2011

Aim 3: Calculate 2's Complement of a WORD.

AREA MY_PROGRAM, CODE

ENTRY

MOV R1, #&AB ; Number


MVN R2, R1 ; R2 = !R1 (1's Complement)
ADD R2, R2, #1 ; R2 = R2 + 1

END

Output:

Page | 3
ARM Processor Programming 2011

Aim 4: Disassemble a BYTE into (high & low) nibbles.

AREA MY_PROGRAM, CODE

ENTRY

MOV R1, #&AB ; Number


AND R2, R1, #&0F ; Mask first 4-bits.
LSR R1, #4 ; Right shift R1 by 4.
AND R3, R1, #&0F ; Mask first 4-bits.

END

Output:

Page | 4
ARM Processor Programming 2011

Aim 5: Find the number of 1’s in a number.

AREA MY_PROGRAM, CODE

ENTRY

LDR R1, =&FF ; Number.


MOV R2, #1 ; MASK.
MOV R3, #0 ; Result.
MOV R4, #32 ; Counter.

LOOP

AND R5, R1, R2 ; Apply MASK.


ADD R3, R3, R5 ; R3 = R3 + R5.
LSR R1, #1 ; Right Shift R3 by 1.
SUBS R4, R4, #1 ; Decrement the counter
BNE LOOP

END

Output:

Page | 5
ARM Processor Programming 2011

Aim 6: Find the lowest number in series.

AREA My_Program, CODE

ENTRY

LDR R1, =SRC ; R1 = Pointer to source.


MOV R2, #10 ;Total numbers.

LDR R3, [R1], #4 ; Load a word from source.

LOOP
LDR R4, [R1], #4 ; Load next word.

CMP R3, R4 ; Compare two words.


MOVGT R3, R4 ; if R4 > R3 then R3 = R4.

SUBS R2, R2, #1 ; Decrement the counter.


BNE LOOP

AREA My_Program_Data, DATA

SRC DCD 5,21,45,12,65,32,7,39,72,3

END

Output:

Page | 6
ARM Processor Programming 2011

Aim 7: Add two packed BCD numbers to give a packed


BCD result.

AREA MY_PROGRAM, CODE, READONLY

ENTRY

LDR R1, =&98765432 ; BCD number 1.


LDR R2, =&23456789 ; BCD number 2.

MOV R5, #0 ; Carry.


MOV R7, #0 ; Packed BCD Result.
MOV R8, #0 ; Offset + Counter.

LOOP
MOV R3, R1 ; Save R1 in R3.
MOV R4, R2 ; Save R2 in R4.

LSR R1, #4 ; Shift right R1 by 4 bits.


LSR R2, #4 ; Shift right R2 by 4 bits.

AND R3, R3, #&0F ; Mask.


AND R4, R4, #&0F ; Mask.

ADD R3, R3, R4 ; Add -> R3 = R3 + R4.


ADD R3, R3, R5 ; Add previous carry.

CMP R3, #10 ; Compare result with 10.

MOVLT R5, #0 ; If R3 < 10 => Carry = 0.


MOVGT R5, #1 ; If R3 > 10 => Carry = 1.
SUBGT R3, R3, #10 ; If R3 >10 => R3=R3-10.

LSL R3, R8 ; Left shift R3 by offset.


ORR R7, R7, R3 ; Place the R3 in R7.

ADD R8, R8, #4 ; Offset increased by 4.

CMP R8, #32 ; Compare offset with 32.

BLT LOOP ; IfR8< 32 => Loop again.

END

Page | 7
ARM Processor Programming 2011

Output:

Page | 8
ARM Processor Programming 2011

Aim 8: Divide two numbers using repeated subtraction.

AREA MY_PROGRAM, CODE, READONLY

ENTRY

MOV R1, #11 ; Dividend.


MOV R2, #2 ; Divisor.
MOV R3, #0 ; Quotient.
MOV R4, #0 ; Remainder.

LOOP

SUB R1, R1, R2 ; Sub -> R1 = R1 - R2.


CMP R1, R2 ; Compare result with
; divisor.

ADD R3, R3, #1 ; Increment quotient by 1.

MOVLT R4, R1 ; If (result < divisor)


; =>Remainder = R1.

BGE LOOP

END

Output:

Page | 9
ARM Processor Programming 2011

Aim 9: Find factorial of a number.

AREA My_Program, CODE

ENTRY

MOV R1, #7 ; Number


MOV R2, #1 ; For Result.

LOOP

CMP R1, #0 ; Compare R1 with 0.

MULNE R2, R1, R2 ; R2 = R2 * R1 iffR1 != 0


SUBSNE R1, R1, #1 ; R2 = R2 - 1 iffR1 != 0

BNE LOOP

END

Output:

Page | 10

You might also like