Home > OS >  Intel 8080 How to convert decimal number to binary and print it
Intel 8080 How to convert decimal number to binary and print it

Time:03-17

i am doing some program in Intel 8080 and in the end i have a number in register E. I need this number convert to binary and print it to terminal.

For now i am printing it like decimal:

mov a,e
adi '0' 
call putchar
call newline
hlt

Can somebody help me how to do that? Ty

CodePudding user response:

Algorithm is - rotate number eight times to left. MSB is moved to CY flag. According CY flag value the digit 1 or 0 is printed. Code assumes that subroutine putchar preserves registers C E

          MVI   c,8   
LOOP:     MOV   a,e   
          RLC           ;rotation to left will print from MSB
          MOV   e,a   
          MVI   a,'0'   
          JNC   zero   
          MVI   a,'1'   
ZERO:     
          CALL   putchar   
          DCR   c   
          JNZ   loop   
          CALL   newline   
          HLT
  • Related