Merge: Nitsmell : Adding new code smells and print console updated
[nit.git] / contrib / pep8analysis / tests / privat / 09-liste.pep
1 ; Programme qui manipule une liste chaînée
2 ; Jean Privat (c) 2010
3 ;
4 ;                            ; // Lit la liste (à l'envers)
5          LDA     10,i        
6          STA     cpt,d       
7 loop_in: CPA     0,i         
8          BRLE    out         ; for(cpt=10; cpt>0; cpt--) {
9          LDA     mLength,i   
10          CALL    new         ;   X = new Maillon(); #mVal #mNext
11          DECI    mVal,x      ;   X.val = getInt();
12          LDA     head,d      
13          STA     mNext,x     ;   X.next = head;
14          STX     head,d      ;   head = X;
15          LDA     cpt,d       
16          SUBA    1,i         
17          STA     cpt,d       
18          BR      loop_in     ; } // fin for
19 ;
20 ;                            ; // Affiche la liste
21 out:     LDX     head,d      
22 loop_out:CPX     0,i         
23          BREQ    fin         ; for (X=head; X!=null; X=X.next) {
24          DECO    mVal,x      
25          CHARO   ' ',i       ;   print(X.val + " ");
26          LDX     mNext,x     
27          BR      loop_out    ; } // fin for
28 fin:     STOP                
29 head:    .BLOCK  2           ; #2h tête de liste (null (aka 0) si liste vide)
30 cpt:     .BLOCK  2           ; #2d compteur de boucle
31 ;
32 ;******* Structure de liste d'entiers
33 ; Une liste est constituée d'une chaîne de maillons.
34 ; Chaque maillon contient une valeur et l'adresse du maillon suivant
35 ; La fin de la liste est marquée arbitrairement par l'adresse 0
36 mVal:    .EQUATE 0           ; #2d valeur de l'élément dans le maillon
37 mNext:   .EQUATE 2           ; #2h maillon suivant (null (aka 0) pour fin de liste)
38 mLength: .EQUATE 4           ; taille d'un maillon en octets
39 ;
40 ;
41 ;******* operator new
42 ;        Precondition: A contains number of bytes
43 ;        Postcondition: X contains pointer to bytes
44 new:     LDX     hpPtr,d     ;returned pointer
45          ADDA    hpPtr,d     ;allocate from heap
46          STA     hpPtr,d     ;update hpPtr
47          RET0                
48 hpPtr:   .ADDRSS heap        ;address of next free byte
49 heap:    .BLOCK  1           ;first byte in the heap
50          .END