Hey guys, first, i wanna say sorry if i'm not making any effort on doing my job here, but im really new to assembly language, i just started like a month ago without any good source.

I got a problem here, i was asked to make a program which a user inputs a decimal value, and can convert the decimal value to hexa, octal and binary.

I already have the codes for each.


Predefined variables

hBuffer 			db 6
						db 0
						db 6 dup(0)
	
	hMultiplier 		db 0ah
	
	oBuffer 			db 6
						db 0
						db 6 dup(0)
	
	oMultiplier 		db 0ah
	
	bBuffer 			db 6
						db 0
						db 6 dup(0)
	
	bMultiplier 		db 0ah

Deci to Hexa

mov ah, 0ah
	lea dx, buffer
	int 21h
	
	mov ah,02h
	mov dh,0Dh
	mov dl,15h
	int 10h
	
	mov dx, offset LblHex1
	mov ah, 09h
	int 21h
	
	mov si, offset hBuffer + 2
	mov cl, byte ptr [si-1]
	mov ch, 00h
	
HexSubtract:
	mov al, byte ptr [si]
	cmp al, 30h
	jnb HexCont1

	mov dx, offset lblInvalid
	mov ah, 09h
	int 21h

	jmp tryH
HexCont1:
	cmp al, 3ah
	jb HexCont2
	mov dx, offset lblInvalid
	mov ah, 09h
	int 21h
	jmp tryH
HexCont2:
	sub al, 30h
	mov byte ptr [si], al

	inc si
	loop HexSubtract

	mov si, offset hBuffer + 2
	mov cl, byte ptr [si-1]
	mov ch, 00h
	mov ax, 0000h
HexCalc:
	mul hMultiplier
	mov bl, byte ptr [si]
	mov bh, 00h
	add ax, bx
	inc si
	loop HexCalc

	mov si, offset hBuffer + 2
	mov bx, ax
	mov dx, 0000h
	mov ax, 1000h
HexConvert:
	mov cx, 0000h
	conv:
	cmp bx, ax
	jb HexCont3
	sub bx, ax
	inc cx
	jmp conv
HexCont3:
	cmp cx, 0ah
	jb HexCont4
	add cl, 37h
	jmp HexCont5
HexCont4:
	add cl, 30h
HexCont5:
	mov byte ptr [si], cl
	inc si
	mov cx, 0010h
	div cx
	cmp ax, 0000h
	jnz HexConvert

	mov byte ptr [si], '$'
	mov dx, offset hBuffer+2
	mov ah, 09h
	int 21h

Deci to Octa

mov ah, 0ah
	lea dx, oBuffer
	int 21h
	
	mov ah,02h
	mov dh,0Dh
	mov dl,15h
	int 10h
	
	mov dx, offset LblOct1
	mov ah, 09h
	int 21h
	
	
	mov si, offset oBuffer + 2
	mov cl, byte ptr [si-1]
	mov ch, 00h
OctSubtract :
	mov al, byte ptr [si]
	cmp al, 30h
	jnb OctCont1
	jmp tryO
OctCont1 :
	cmp al, 3ah
	jb OctCont2
	jmp tryO
OctCont2 :
	sub al, 30h
	mov byte ptr [si], al

	inc si
	loop OctSubtract

	mov si, offset oBuffer + 2
	mov cl, byte ptr [si-1]
	mov ch, 00h
	mov ax, 0000h
OctCalc :
	mul oMultiplier
	mov bl, byte ptr [si]
	mov bh, 00h
	add ax, bx
	inc si
	loop OctCalc

	mov si, offset oBuffer + 2
	mov bx, ax
	mov dx, 0000h
	mov ax, 8000h
OctOctConvert :
	mov cx, 0000h
OctConv :
	cmp bx, ax
	jb OctCont3
	sub bx, ax
	inc cx
	jmp OctConv
OctCont3 :
	add cl, 30h
	mov byte ptr [si], cl
	inc si
	mov cx, 0008h
	div cx
	cmp ax, 0000h
	jnz OctOctConvert

	mov byte ptr [si], '$'
	mov dx, offset oBuffer+2
	mov ah, 09h
	int 21h

Deci to Bin

mov ah, 0ah
	lea dx, bBuffer
	int 21h
	
	mov ah,02h
	mov dh,0Dh
	mov dl,15h
	int 10h
	
	mov dx, offset LblBin1
	mov ah, 09h
	int 21h
	
	mov si, offset bBuffer + 2
	mov cl, byte ptr [si-1]
	mov ch, 00h
BinSubtract :
	mov al, byte ptr [si]
	cmp al, 30h
	jnb BinCont1
	jmp tryB
BinCont1 :
	cmp al, 3ah
	jb BinCont2
	jmp tryB
BinCont2 :
	sub al, 30h
	mov byte ptr [si], al

	inc si
	loop BinSubtract

	mov si, offset bBuffer + 2
	mov cl, byte ptr [si-1]
	mov ch, 00h
	mov ax, 0000h
BinCalc :
	mul bMultiplier
	mov bl, byte ptr [si]
	mov bh, 00h
	add ax, bx
	inc si
	loop BinCalc

	mov si, offset bBuffer + 2
	mov bx, ax
	mov dx, 0000h
	mov ax, 8000h
BinBinConvert :
	mov cx, 0000h
BinConv :
	cmp bx, ax
	jb BinCont3
	sub bx, ax
	inc cx
	jmp BinConv
BinCont3 :
	add cl, 30h
	mov byte ptr [si], cl
	inc si
	mov cx, 0002h
	div cx
	cmp ax, 0000h
	jnz BinBinConvert

	mov byte ptr [si], '$'
	mov dx, offset bBuffer+2
	mov ah, 09h
	int 21h

Don't mind the pre-declared variables because, this are just parts from my program. Wherein, this three are parts of one menu option.

The question is, whenver I put a "TRY/AGAIN" function(asks user if y/n, if yes, 'jumps' back to this menu, if n, goes back to the very first menu), the value that the hexa, octal, and binary stacks.

SCENARIO:
[1]Deci to Hex
[2]Deci to Octal
[3]Deci to Binary

user inputs 1(for hexadecimal conversion)
user inputs 10(decimal)
program displays 000A(which is correct)
program asks if user wants to try again
user inputs y
goes back to the same menu

user inputs 3(for binary conversion)
user inputs 10(decimal)
program displays 00001010(which is correct)
program asks if user wants to try again
user inputs y
goes back to the same menu

user inputs 1(for hexadecimal conversion)
user inputs 10(decimal)
program displays 030(which is correct)
program asks if user wants to try again
user exits program

And the same with octal, but in hexadecimal, it outputs 0024.

Any help would be appreciated, i'll try to cope up but to remind you, i just started studying assembly last month.

EDIT: Included the pre-defined variables.

Each digit is a multiple of a power of ten.
the 4th digit of 9,321 is 9*10^3. Sum each of
these multiples of powers of ten (the base) and
you'll have the binary equivalent of the value.

If the digits were entered as ASCII subtract 30H (48d)
to turn it into an unpacked BCD: 01, 02, 03, 04, 07...

After converting it into an unsigned binary value
it is pretty simple to turn it then into hexadecimal and
octal being that base 16 and 8 are compact representations
of binary.

So that:
15 = 0000 1111 = 0F Hex
0 001 111 = 17 Octal

Hope that helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.