IASCIIHE.PAS 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. (* programme comment‚ et expliqu‚ dans le livre *)
  2. (* LE DESASSEMBLEUR 8086 COLIBRI, publi‚ par *)
  3. (* L'INSTITUT PASCAL: *)
  4. (* 26 Rue Lamartine, 75009 PARIS *)
  5. (* Tel: (1) 42.85.10.82 *)
  6. procedure desassemble_ascii(p_adresse_debut, p_adresse_fin: integer);
  7. var l_reste, l_quantite_a_imprimer, l_quantite_imprimee: integer;
  8. l_octet: byte;
  9. l_controle: boolean;
  10. l_premiere_ligne: boolean;
  11. l_ligne: string80;
  12. l_indice: integer;
  13. procedure traite_controle;
  14. begin
  15. if l_ligne<> ''
  16. then begin
  17. if b_avec_octets_hexadecimaux
  18. then begin
  19. for l_indice:= l_quantite_imprimee+ 1 to 8 do
  20. write(sortie, ' ');
  21. write(sortie, ' ', numero_ligne- 2:4, ' ');
  22. end;
  23. write(sortie, nom_debut_ligne, ' asc ''', l_ligne, '''');
  24. writeln(sortie);
  25. if b_avec_octets_hexadecimaux
  26. then write(sortie, f_entier_hexadecimal(adresse- 1), ' ');
  27. if l_premiere_ligne
  28. then begin
  29. l_premiere_ligne:= false;
  30. nom_debut_ligne:= ' ';
  31. end;
  32. l_reste:= l_reste- l_quantite_imprimee;
  33. l_quantite_imprimee:= 0;
  34. end;
  35. l_ligne:= f_octet_hexadecimal(l_octet);
  36. end;
  37. begin
  38. adresse:= p_adresse_debut;
  39. l_reste:= p_adresse_fin+ 1- p_adresse_debut;
  40. nom_debut_ligne:= f_label_debut_ligne(adresse);
  41. l_premiere_ligne:= true;
  42. while l_reste> 0 do
  43. begin
  44. writeln(sortie);
  45. if b_avec_octets_hexadecimaux
  46. then write(sortie, f_entier_hexadecimal(adresse), ' ');
  47. l_ligne:= '';
  48. l_quantite_a_imprimer:= l_reste;
  49. if l_quantite_a_imprimer> 8
  50. then l_quantite_a_imprimer:= 8;
  51. l_controle:= false;
  52. l_quantite_imprimee:= 0;
  53. repeat
  54. lis_octet_suivant(l_octet);
  55. l_quantite_imprimee:= l_quantite_imprimee+ 1;
  56. if not (l_octet in [32..127])
  57. then begin
  58. traite_controle;
  59. l_controle:= true;
  60. end
  61. else l_ligne:= concat(l_ligne, chr(l_octet));
  62. until l_controle or (l_quantite_imprimee>= l_quantite_a_imprimer);
  63. if b_avec_octets_hexadecimaux
  64. then begin
  65. for l_indice:= l_quantite_imprimee+ 1 to 8 do
  66. write(sortie, ' ');
  67. write(sortie, ' ', numero_ligne:4, ' ');
  68. end;
  69. if l_controle
  70. then write(sortie, nom_debut_ligne, ' hex ', l_ligne)
  71. else write(sortie, nom_debut_ligne, ' asc ''', l_ligne, '''');
  72. l_reste:= l_reste- l_quantite_imprimee;
  73. if l_premiere_ligne
  74. then begin
  75. l_premiere_ligne:= false;
  76. nom_debut_ligne:= ' ';
  77. end;
  78. numero_ligne:= numero_ligne+ 1;
  79. if b_stop_ecran and (numero_ligne mod 20= 0)
  80. then stop;
  81. end;
  82. writeln(sortie);
  83. end;
  84. procedure desassemble_hex(p_adresse_debut, p_adresse_fin: integer);
  85. var l_reste, l_quantite: integer;
  86. l_octet: byte;
  87. l_premiere_ligne: boolean;
  88. l_indice: integer;
  89. l_ligne: string80;
  90. begin
  91. adresse:= p_adresse_debut;
  92. l_reste:= p_adresse_fin+ 1- p_adresse_debut;
  93. nom_debut_ligne:= f_label_debut_ligne(adresse);
  94. l_premiere_ligne:= true;
  95. while l_reste> 0 do
  96. begin
  97. writeln(sortie);
  98. if b_avec_octets_hexadecimaux
  99. then write(sortie, f_entier_hexadecimal(adresse), ' ');
  100. l_ligne:= '';
  101. l_quantite:= l_reste;
  102. if l_quantite> 8
  103. then l_quantite:= 8;
  104. for l_indice:= 1 to l_quantite do
  105. begin
  106. lis_octet_suivant(l_octet);
  107. l_ligne:= concat(l_ligne, f_octet_hexadecimal(l_octet));
  108. end;
  109. if b_avec_octets_hexadecimaux
  110. then begin
  111. for l_indice:= l_quantite+1 to 8 do
  112. write(sortie, ' ');
  113. write(sortie, ' ', numero_ligne:4, ' ');
  114. end;
  115. write(sortie, nom_debut_ligne, ' hex ', l_ligne);
  116. if l_premiere_ligne
  117. then begin
  118. l_premiere_ligne:= false;
  119. nom_debut_ligne:= ' ';
  120. end;
  121. l_reste:= l_reste- l_quantite;
  122. numero_ligne:= numero_ligne+ 1;
  123. if b_stop_ecran and (numero_ligne mod 20= 0)
  124. then stop;
  125. end;
  126. writeln(sortie);
  127. end;