ARM Simple Programs in Assembly

Simple Programs in Assembly


SERIES ADDITION OF 'N' 32 BIT NUMBERS


AREA program, CODE, readwrite
 ENTRY
  LDR R1, N  ;Load Counter
  LDR R2, =NOS  ;Initialize the Pointer
  MOV R0, #0  ;Clear Register to hold result
LOOP  LDR R3,[R2],#4  ;Load the number to register
  ADD R0, R0, R3  ;Addition of nos.
  SUBS R1, R1,#1  ;Decerement counter
  BNE LOOP  ;Check counter = 0
  STR R0,RESULT  ;Store result
HERE  B HERE  

 AREA storage , data, readwrite
N   DCD 0x05
NOS  DCD 05,06,07,08,09
RESULT DCD 0x0
  END

To find the largest number from series of numbers


AREA program, CODE, readwrite
 ENTRY
  LDR R1, N  ;Load Counter
  LDR R2, =NOS  ;Initialize the Pointer
  MOV R0, #0  ;Clear Register to hold result
LOOP  LDR R3,[R2],#4  ;Load the number to register
  CMP R3, R0  ;Compare the number
  BLO SKIP   ;Skip if number is smaller
  MOV R0, R3  ;Load largest number in result register
SKIP  SUBS R1, R1,#1  ;Decerement Counter
  BNE LOOP  ;Check Counter = 0
  STR R0,RESULT  ;Store the result
HERE  B HERE
 AREA storage, data, readwrite
N   DCD 0x05
NOS  DCD 05, 10,09, 08, 07
RESULT DCD 0x0
 END

To find the samallest number from series of numbers


AREA program, CODE, readwrite
 ENTRY
  LDR R1, N  ;Load Counter
  LDR R2, =NOS  ;Initialize the Pointer
  LDR R0, [R2],#4  ;Load First Number
  SUBS R1, R1,#1  ;Decrement counter
LOOP  LDR R3, [R2],#4  ;Load Next Number
  CMP R3, R0  ;Compare the numbers
  BCS SKIP   ;Skip if carry set
  MOV R0, R3  ;Load the smallest number
SKIP  SUBS R1, R1,#1  ;Decrement Counter
  BNE LOOP  ;Check counter = 0
  STR R0,SUM  ;Store result
HERE  B HERE
 AREA program, CODE, readwrite
N   DCD 0x05
NOS  DCD 05, 10,09, 08, 07
RESULT DCD 0x0
 END

Program to find the Positive numbers from series of numbers


AREA program, CODE, readwrite           ; Defining Program Area with readwrite permission
 ENTRY
            LDR R1, N                               ;Load Counter
            LDR R2, =NOS                        ;Initialize the Pointer
            MOV R0, #0                            ;Clear Register to hold result
LOOP LDR R3,[R2],#4                      ;Load the number to register
            ANDS R3,#0x80000000         ; Check for MSB = 1
            ADDEQ R0, R0, #1                 ;if MSB=0 then increment
SKIP    SUBS R1, R1,#1                      ;Decrement Counter
            BNE LOOP                              ;Check counter = 0
            STR R1,RESULT                     ;Store result
HERE    B HERE
 AREA storage, data, readwrite                        ; Defining storage Area with readwrite permission
N   DCD  0x0A                                                ;Store the count of nos. in N
NOS  DCD -5,6,-9,8,7,1,2,3,-4,-7        ;Store the 10 nos. with sign in array
RESULT DCD 0                                  ;Initialize resukt variable with value 0
           END


Program to find the Negative numbers from series of numbers


AREA program, CODE, read write
 ENTRY
  LDR R1, N  ;Load Counter
  LDR R2, =NOS  ;Initialize the Pointer
  MOV R0, #0  ;Clear Register to hold result
LOOP  LDR R3,[R2],#4  ;Load the number to register
  ANDS R3,#0x80000000  ; Check for MSB = 1
  ADDNE R0, R0, #1  ;if MSB=1 then increment
SKIP  SUBS R1, R1,#1  ;Decrement Counter
  BNE LOOP  ;Check counter = 0
  STR R0,RESULT  ;Store result
HERE  B HERE
 AREA storage, data, read write
N   DCD 0x05
NOS  DCD -5,6,-9, 8, 7
RESULT DCD 0x0

 END

References


  • WikiNote Foundation

Last modified: Monday, 23 March 2020, 9:28 PM