8086 Microprocessor using Debug (hex to bin conversion)

Discussion in 'Programmer's Corner' started by Reshma, Dec 16, 2007.

  1. Reshma

    Thread Starter Active Member

    Mar 11, 2007
    54
    0
    Expert needed here!!

    I have to write an 8086 program using MS-Dos Debug utility. The program is to convert a given hexadecimal number into its binary form and display the result on the screen. This my program but somehow it prints some absurd result on the screen. Someone please check out my program and discover the problem.

    Code ( (Unknown Language)):
    1.  
    2.           MOV AH,02 ;Displays the contents of DL register
    3.           MOV DL,00
    4.           MOV CL,08 ;Counter for the 8-bit number
    5.           MOV BL,XX ;8 bit Hex number to be converted
    6.  Again     RCL BL,1    ;Rotate BL through Carry
    7.           ADC DL,30  ;Add contents of DL and 30 with carry
    8.           INT21        ;Displays contents of DL (30/31 = Ascii code of 0/1)
    9.           LOOP Again
    10.           INT20        ;Terminate the program
    11.  
    Please check whether this program is correct because it doesn't work for me.
     
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    Right off, there is no condition that will terminate the loop. You have a counter for the 8 bits, but do not use it.
     
  3. mrmeval

    Distinguished Member

    Jun 30, 2006
    833
    2
    Oh, you have one of those teachers. Use an assembler and make a com file then run the com file through a converter that will output a debug script.

    http://eradicus.blogsome.com/2006/08/13/hex-to-bin-converter-in-16-bit-dos-assembly/

    input:
    mov ah, 00h
    int 16h
    cmp ah, 1ch
    je exit

    number:
    cmp al, '0'
    jb input
    cmp al, '9'
    ja uppercase
    sub al, 30h
    call process
    jmp input

    uppercase:
    cmp al, 'A'
    jb input
    cmp al, 'F'
    ja lowercase
    sub al, 37h
    call process
    jmp input

    lowercase:
    cmp al, 'a'
    jb input
    cmp al, 'f'
    ja input
    sub al, 57h
    call process
    jmp input

    loop input

    process:
    mov ch, 4
    mov cl, 3
    mov bl, al

    convert:
    mov al, bl
    ror al, cl
    and al, 01
    add al, 30h

    mov ah, 02h
    mov dl, al
    int 21h

    dec cl
    dec ch
    jnz convert

    mov dl, 20h
    int 21h
    ret

    exit:
    int 20h
     
  4. Reshma

    Thread Starter Active Member

    Mar 11, 2007
    54
    0
    I have used the LOOP instruction. The LOOP instruction is equivalent of performing a given action till the counter variable CX is zero.
     
  5. Reshma

    Thread Starter Active Member

    Mar 11, 2007
    54
    0
    mrmeval, I have read your post. It is something new and I have never been taught. But unfortunately for me....my teachers expect me to use the same debug DOS utility for all the 8086 programming :(. I will try to grasp your program nevertheless. Thanks.
     
  6. RiJoRI

    Well-Known Member

    Aug 15, 2007
    536
    26
    Code ( (Unknown Language)):
    1.  
    2.           MOV AH,02 ;Displays the contents of DL register
    3.           MOV DL,00
    4.           MOV CL,08 ;Counter for the 8-bit number
    5.           MOV BL,XX ;8 bit Hex number to be converted
    6.  Again     RCL BL,1    ;Rotate BL through Carry
    7.           ADC DL,30  ;Add contents of DL and 30 with carry
    8.           INT21        ;Displays contents of DL (30/31 = Ascii code of 0/1)
    9.           LOOP Again
    10.           INT20        ;Terminate the program
    11.  
    First time: DL = $30+[0|1]
    Second time: DL = DL + $30+[0|1]

    The DL register should be cleared inside the loop.

    --Rich
     
  7. Reshma

    Thread Starter Active Member

    Mar 11, 2007
    54
    0
    Thanks, that was the reason my program kept throwing garbage values. It was a misplaced instruction that caused the problem. The DL register should be cleared after every loop execution.
     
Loading...