8086 Microprocessor using Debug (hex to bin conversion)

Thread Starter

Reshma

Joined Mar 11, 2007
54
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.

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

mrmeval

Joined Jun 30, 2006
833
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
 

Thread Starter

Reshma

Joined Mar 11, 2007
54
Right off, there is no condition that will terminate the loop. You have a counter for the 8 bits, but do not use it.
I have used the LOOP instruction. The LOOP instruction is equivalent of performing a given action till the counter variable CX is zero.
 

Thread Starter

Reshma

Joined Mar 11, 2007
54
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.
 

RiJoRI

Joined Aug 15, 2007
536
Rich (BB code):
          MOV AH,02 ;Displays the contents of DL register
          MOV DL,00
          MOV CL,08 ;Counter for the 8-bit number
          MOV BL,XX ;8 bit Hex number to be converted
 Again     RCL BL,1    ;Rotate BL through Carry
          ADC DL,30  ;Add contents of DL and 30 with carry
          INT21        ;Displays contents of DL (30/31 = Ascii code of 0/1)
          LOOP Again
          INT20        ;Terminate the program
First time: DL = $30+[0|1]
Second time: DL = DL + $30+[0|1]

The DL register should be cleared inside the loop.

--Rich
 

Thread Starter

Reshma

Joined Mar 11, 2007
54
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.
 
Top