The anti-primes
(or highly composite numbers, sequence A002182 in the OEIS)
are the natural numbers with more factors than any smaller than itself.



Task

Generate and show here, the first twenty anti-primes.



Related tasks

   Factors of an integer
   Sieve of Eratosthenes


 
/* ARM assembly Raspberry PI or android with termux */
/*  program antiprime.s   */
 
 /* REMARK 1 : this program use routines in a include file 
   see task Include a file language arm assembly 
   for the routine affichageMess conversion10 
   see at end of this program the instruction include */
/* for constantes see task include a file in arm assembly */
/************************************/
/* Constantes                       */
/************************************/
.include "../constantes.inc"
 
.equ NMAXI,      20
.equ MAXLINE,     5
/*********************************/
/* Initialized data              */
/*********************************/
.data
sMessResult:        .asciz " @ "
szCarriageReturn:   .asciz "\n"
/*********************************/
/* UnInitialized data            */
/*********************************/
.bss  
sZoneConv:                  .skip 24
/*********************************/
/*  code section                 */
/*********************************/
.text
.global main 
main:                             @ entry of program 
    ldr r3,iNMaxi                 @ load limit
    mov r5,#0                     @ maxi
    mov r6,#0                     @ result counter
    mov r7,#0                     @ display counter
    mov r4,#1                     @ number begin
1:
    mov r0,r4                     @ number
    bl decFactor                  @ compute number factors
    cmp r0,r5                     @ maxi ?
    addle r4,r4,#1                @ no -> increment indice
    ble 1b                        @ and loop
    mov r5,r0
    mov r0,r4
    bl displayResult
    add r7,r7,#1                  @ increment display counter
    cmp r7,#MAXLINE               @ line maxi ?
    blt 2f
    mov r7,#0
    ldr r0,iAdrszCarriageReturn
    bl affichageMess              @ display message
2:
    add r6,r6,#1                  @ increment result counter
    add r4,r4,#1                  @ increment number
    cmp r6,r3                     @ end ?
    blt 1b
 
100:                              @ standard end of the program 
    mov r0, #0                    @ return code
    mov r7, #EXIT                 @ request to exit program
    svc #0                        @ perform the system call
iAdrszCarriageReturn:        .int szCarriageReturn
iNMaxi:                       .int NMAXI
/***************************************************/
/*   display message number                        */
/***************************************************/
/* r0 contains number 1           */
/* r1 contains number 2               */
displayResult:
    push {r1,lr}               @ save registers 
    ldr r1,iAdrsZoneConv
    bl conversion10            @ call décimal conversion
    ldr r0,iAdrsMessResult
    ldr r1,iAdrsZoneConv       @ insert conversion in message
    bl strInsertAtCharInc
 
    bl affichageMess           @ display message
    pop {r1,pc}                @ restaur des registres
iAdrsMessResult:     .int sMessResult
iAdrsZoneConv:       .int sZoneConv
/***************************************************/
/*   compute factors sum                        */
/***************************************************/
/* r0 contains the number            */
decFactor:
    push {r1-r5,lr}           @ save registers 
    mov r5,#0                 @ init number factors
    mov r4,r0                 @ save number
    mov r1,#1                 @ start factor -> divisor
1:
    mov r0,r4                 @ dividende
    bl division
    cmp r1,r2                 @ divisor > quotient ?
    bgt 3f
    cmp r3,#0                 @ remainder = 0 ?
    bne 2f
    add r5,r5,#1              @ increment counter factors
    cmp r1,r2                 @ divisor = quotient ?
    beq 3f                    @ yes -> end
    add r5,r5,#1              @ no -> increment counter factors
2:
    add r1,r1,#1              @ increment factor
    b 1b                      @ and loop
3:
    mov r0,r5                 @ return counter
    pop {r1-r5,pc}            @ restaur registers
 
/***************************************************/
/*      ROUTINES INCLUDE                           */
/***************************************************/
.include "../affichage.inc"
 