0

this is my code so far.

I am really confused and im having a hard time using pep8. I need to convert a number to a chosen base. e.g. 343 to base 2

     LDA    0,i 
     LDX    0,i
     STRO   prompt,d
     DECI   base,d       ;base = getInt();
     LDA    base,d            
     BRLT   pluPetit     ;vérifie si nombre < 0 {
     STRO   baseMsg,d    ;affiche msg
     DECI   conv,d       ;conv = getInt();
     STOP                ;exit(); }
    pluPetit:STRO   negMsg,d     ;affiche msg d'erreur si nombre < 0



     STOP
   base:    .WORD   0
   conv:    .WORD   0
   prompt:  .ASCII  "Entrez un nombre positif svp: \x00"
   negMsg:  .ASCII  "Entrée invalide\n \x00"
   baseMsg: .ASCII  "Entrez une base de conversion (un nombre de 
              2 à 36): \X00"
   result:  .ASCII  "Résultat: \x00"
   table:   .ASCII  "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" 
  ;caractères pour base 36 

maxNum:  .EQUATE  32767
minBase: .EQUATE  2
maxBase: .EQUATE  36


     .END

I tried a different loops

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
adam123
  • 1
  • 1
  • The algorithm you need is just divide and modulo. [How do I print an integer in Assembly Level Programming without printf from the c library? (itoa, integer to decimal ASCII string)](https://stackoverflow.com/a/46301894) shows C. I assume pep8 doesn't have a divide instruction (like many real-world microcontroller ISAs, and some older CPUs), so you'd need a loop for that. If it has a right-shift instruction and bitwise instructions, power-of-2 bases are much easier and more efficient. – Peter Cordes Feb 09 '23 at 07:04

0 Answers0