Rekch

Untitled

Apr 17th, 2018
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. ;
  2. ; ; // Lit la liste (à l'envers)
  3. LDA 5,i
  4. STA taille,d
  5. STA cpt,d
  6. loop_in: CPA 0,i
  7. BRLE out ; for(cpt=5; cpt>0; cpt--) {
  8. LDA mLength,i
  9. CALL new ; X = new Maillon(); #mVal #mNext
  10. CHARI caract,d ; X.val = getInt();
  11. LDA 0,i
  12. LDBYTEA caract,d ;analyse du caractère lu
  13. STA mVal,x
  14. LDA head,d
  15. STA mNext,x ; X.next = head;
  16. STX head,d ; head = X;
  17. LDA cpt,d
  18. SUBA 1,i
  19. STA cpt,d
  20. BR loop_in ; } // fin for
  21. ;
  22. ; ; // Affiche la liste
  23.  
  24.  
  25.  
  26. out: LDX head,d
  27. STX index,d
  28. STX min,d
  29. comp: LDX index,d
  30. LDA mVal,x
  31. LDX min,d
  32. CPA mVal,x
  33. BRLT changem
  34. BR tmax
  35.  
  36. changem: LDA index,d
  37. STA min,d
  38. BR tmax
  39.  
  40.  
  41. tmax: LDX index,d
  42. LDX mNext,x
  43. STX index,d
  44. LDX index,d
  45. CPX 0,i
  46. BREQ impr
  47. BR comp
  48.  
  49. impr: LDX min,d
  50. CHARO mVal,x
  51. LDA 'z',i
  52. STA mVal,x
  53. LDA taille,d
  54. SUBA 1,i
  55. STA taille,d
  56. LDA taille,d
  57. CPA 0,i
  58. BREQ fin
  59. BR out
  60.  
  61.  
  62. fin: STOP
  63.  
  64. caract: .BLOCK 1 ; #1h
  65. vide: .BLOCK 1 ;
  66. head: .BLOCK 2 ; #2h tête de liste (null (aka 0) si liste vide)
  67. cpt: .BLOCK 2 ; #2d compteur de boucle
  68. taille: .BLOCK 2 ; #2d
  69. index: .BLOCK 2 ; #2d
  70. min: .BLOCK 2 ; #2d
  71. ;
  72. ;******* Structure de liste d'entiers
  73. ; Une liste est constituée d'une chaîne de maillons.
  74. ; Chaque maillon contient une valeur et l'adresse du maillon suivant
  75. ; La fin de la liste est marquée arbitrairement par l'adresse 0
  76. mVal: .EQUATE 0 ; #1h valeur de l'élément dans le maillon
  77. mNext: .EQUATE 1 ; #2h maillon suivant (null (aka 0) pour fin de liste)
  78. mLength: .EQUATE 3 ; taille d'un maillon en octets
  79. ;
  80. ;
  81. ;******* operator new
  82. ; Precondition: A contains number of bytes
  83. ; Postcondition: X contains pointer to bytes
  84. new: LDX hpPtr,d ;returned pointer
  85. ADDA hpPtr,d ;allocate from heap
  86. STA hpPtr,d ;update hpPtr
  87. RET0
  88. hpPtr: .ADDRSS heap ;address of next free byte
  89. heap: .BLOCK 1 ;first byte in the heap
  90. .END
Add Comment
Please, Sign In to add comment