How to resolve the algorithm Count in factors step by step in the 360 Assembly programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Count in factors step by step in the 360 Assembly programming language

Table of Contents

Problem Statement

Write a program which counts up from   1,   displaying each number as the multiplication of its prime factors. For the purpose of this task,   1   (unity)   may be shown as itself.

2   is prime,   so it would be shown as itself.       6   is not prime;   it would be shown as

2 × 3

{\displaystyle 2\times 3}

. 2144   is not prime;   it would be shown as

2 × 2 × 2 × 2 × 2 × 67

{\displaystyle 2\times 2\times 2\times 2\times 2\times 67}

.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Count in factors step by step in the 360 Assembly programming language

Source code in the 360 programming language

*        Count in factors          24/03/2017
COUNTFAC CSECT                     assist plig\COUNTFAC
         USING  COUNTFAC,R13       base register
         B      72(R15)            skip savearea
         DC     17F'0'             savearea
         STM    R14,R12,12(R13)    save previous context
         ST     R13,4(R15)         link backward
         ST     R15,8(R13)         link forward
         LR     R13,R15            set addressability
         L      R6,=F'1'           i=1
       DO WHILE=(C,R6,LE,=F'40')   do i=1 to 40
         LR     R7,R6                n=i
         MVI    F,X'01'              f=true
         MVC    PG,=CL80' '          clear buffer
         LA     R10,PG               pgi=0
         XDECO  R6,XDEC              edit i
         MVC    0(12,R10),XDEC       output i
         LA     R10,12(R10)          pgi=pgi+12
         MVC    0(1,R10),=C'='       output '='
         LA     R10,1(R10)           pgi=pgi+1
       IF C,R7,EQ,=F'1' THEN         if n=1 then
         MVI    0(R10),C'1'            output n
       ELSE     ,                    else
         LA     R8,2                   p=2
       DO WHILE=(CR,R8,LE,R7)          do while p<=n 
         LR     R4,R7                    n
         SRDA   R4,32                    ~
         DR     R4,R8                    /p
       IF LTR,R4,Z,R4 THEN               if n//p=0 then
       IF CLI,F,EQ,X'00' THEN              if not f then
         MVC    0(1,R10),=C'*'               output '*'
         LA     R10,1(R10)                   pgi=pgi+1
       ELSE     ,                          else
         MVI    F,X'00'                      f=false
       ENDIF    ,                          endif
         CVD    R8,PP                      convert bin p to packed pp
         MVC    WORK12,MASX12              in fact L13
         EDMK   WORK12,PP+2                edit and mark
         LA     R9,WORK12+12               end of string(p)
         SR     R9,R1                      li=lengh(p)  {r1 from edmk}
         MVC    EDIT12,WORK12              L12<-L13
         LA     R4,EDIT12+12               source+12
         SR     R4,R9                      -lengh(p)
         LR     R5,R9                      lengh(p) 
         LR     R2,R10                     target ix
         LR     R3,R9                      lengh(p) 
         MVCL   R2,R4                      f=f||p
         AR     R10,R9                     ix=ix+lengh(p)
         LR     R4,R7                      n
         SRDA   R4,32                      ~
         DR     R4,R8                      /p
         LR     R7,R5                      n=n/p
       ELSE     ,                        else
         LA     R8,1(R8)                   p=p+1
       ENDIF    ,                        endif
       ENDDO    ,                      enddo while
       ENDIF    ,                    endif
         XPRNT  PG,L'PG              print buffer
         LA     R6,1(R6)             i++
       ENDDO    ,                  enddo i
         L      R13,4(0,R13)       restore previous savearea pointer
         LM     R14,R12,12(R13)    restore previous context
         XR     R15,R15            rc=0
         BR     R14                exit
F        DS     X                  flag first factor
         DS     0D                 alignment for cvd
PP       DS     PL8                packed  CL8
EDIT12   DS     CL12               target  CL12
WORK12   DS     CL13               char    CL13
MASX12   DC     X'40',9X'20',X'212060'     CL13
XDEC     DS     CL12               temp
PG       DS     CL80               buffer
         YREGS
         END    COUNTFAC

  

You may also check:How to resolve the algorithm Narcissistic decimal number step by step in the Factor programming language
You may also check:How to resolve the algorithm Letter frequency step by step in the PureBasic programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the MAD programming language
You may also check:How to resolve the algorithm Huffman coding step by step in the Zig programming language
You may also check:How to resolve the algorithm Date format step by step in the COBOL programming language