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 ENTRY MOV MOV ADD LDR STR AREA DEST DCD END R2, #2 R3, #3 R1, R2, R3 R4, =DEST R1, [R4] ; First Number ; Second Number ; R1 = R2 + R3 ; R4 = pointer to DEST. ;Store R1 at DEST. MY_PROGRAM, CODE

MY_PROGRAM_Data, DATA 0

Output:

Page | 1

ARM Processor Programming 2011 Aim 2: Add two 64-bit numbers.
AREA ENTRY LDR LDR LDR LDR ADDS ADC END R1, R2, R3, R4, =&ABCDEFAB =&00000001 =&00000001 =&00000001 ; ; ; ; First number (63-32) First number (31-0) Second number (63-32) Second number (31-0) MY_PROGRAM, CODE

R3, R3, R1 R4, R4, R2

Output:

Page | 2

ARM Processor Programming 2011 Aim 3: Calculate 2's Complement of a WORD.
AREA ENTRY MOV MVN ADD END Output: R1, #&AB R2, R1 R2, R2, #1 ; Number ; R2 = !R1 (1's Complement) ; R2 = R2 + 1 MY_PROGRAM, CODE

Page | 3

ARM Processor Programming 2011 Aim 4: Disassemble a BYTE into (high & low) nibbles.
AREA ENTRY MOV AND LSR AND END Output: R1, R2, R1, R3, #&AB R1, #&0F #4 R1, #&0F ; ; ; ; Number Mask first 4-bits. Right shift R1 by 4. Mask first 4-bits. MY_PROGRAM, CODE

Page | 4

ARM Processor Programming 2011 Aim 5: Find the number of 1’s in a number.
AREA ENTRY LDR MOV MOV MOV LOOP AND ADD LSR SUBS BNE LOOP END Output: R5, R3, R1, R4, R1, R2 R3, R5 #1 R4, #1 ; ; ; ; Apply MASK. R3 = R3 + R5. Right Shift R3 by 1. Decrement the counter R1, R2, R3, R4, =&FF #1 #0 #32 ; ; ; ; Number. MASK. Result. Counter. MY_PROGRAM, CODE

Page | 5

ARM Processor Programming 2011 Aim 6: Find the lowest number in series.
AREA ENTRY LDR MOV LDR LOOP LDR CMP MOVGT SUBS BNE AREA SRC END DCD LOOP My_Program_Data, DATA 5,21,45,12,65,32,7,39,72,3 R4, [R1], #4 R3, R4 R3, R4 R2, R2, #1 ; Load next word. ; Compare two words. ; if R4 > R3 then R3 = R4. ; Decrement the counter. R1, =SRC R2, #10 ; R1 = Pointer to source. ;Total numbers. ; Load a word from source. My_Program, CODE

R3, [R1], #4

Output:

Page | 6

ARM Processor Programming 2011 Aim 7: Add two packed BCD numbers to give a packed BCD result.
AREA ENTRY LDR LDR MOV MOV MOV LOOP MOV MOV LSR LSR AND AND ADD ADD CMP MOVLT MOVGT SUBGT LSL ORR ADD CMP BLT END Page | 7 R3, R1 R4, R2 R1, #4 R2, #4 R3, R3, #&0F R4, R4, #&0F ; Save R1 in R3. ; Save R2 in R4. ; Shift right R1 by 4 bits. ; Shift right R2 by 4 bits. ; Mask. ; Mask. R1, =&98765432 ; BCD number 1. R2, =&23456789 ; BCD number 2. R5, #0 R7, #0 R8, #0 ; Carry. ; Packed BCD Result. ; Offset + Counter. MY_PROGRAM, CODE, READONLY

R3, R3, R4 ; Add -> R3 = R3 + R4. R3, R3, R5 ; Add previous carry. R3, #10 R5, #0 R5, #1 R3, R3, #10 R3, R8 R7, R7, R3 R8, R8, #4 R8, #32 LOOP ; Compare result with 10. ; If R3 < 10 => Carry = 0. ; If R3 > 10 => Carry = 1. ; If R3 >10 => R3=R3-10. ; Left shift R3 by offset. ; Place the R3 in R7. ; Offset increased by 4. ; Compare offset with 32. ; IfR8< 32 => Loop again.

ARM Processor Programming 2011

Output:

Page | 8

ARM Processor Programming 2011 Aim 8: Divide two numbers using repeated subtraction.

AREA ENTRY MOV MOV MOV MOV LOOP SUB CMP

MY_PROGRAM, CODE, READONLY

R1, R2, R3, R4,

#11 #2 #0 #0

; ; ; ;

Dividend. Divisor. Quotient. Remainder.

R1, R1, R2 R1, R2

; Sub -> R1 = R1 - R2. ; Compare result with ; divisor. ; Increment quotient by 1. ; If (result < divisor) ; =>Remainder = R1.

ADD MOVLT

R3, R3, #1 R4, R1

BGE END

LOOP

Output:

Page | 9

ARM Processor Programming 2011 Aim 9: Find factorial of a number.
AREA ENTRY MOV MOV LOOP CMP MULNE SUBSNE BNE END Output: R1, #0 R2, R1, R2 R1, R1, #1 LOOP ; Compare R1 with 0. ; R2 = R2 * R1 iffR1 != 0 ; R2 = R2 - 1 iffR1 != 0 R1, #7 R2, #1 ; Number ; For Result. My_Program, CODE

Page | 10

Sign up to vote on this title
UsefulNot useful