[emu8086] Hex2Dec

I`m using emu8086 emulator and trying to convert 2 diggit hex number to dec but cant figure out how to print it.
For example i have hex = AB, so A *16 + B (A=10, B=11). But the result is in hex. Any example how can i print it in dec ?

Here is what i`we done already:
[code]
#MAKE_EXE#

DSEG SEGMENT 'DATA'

MSG DB 'Insert 2 diggit HEX number: $'
MSG2 DB 'Worng number $'
MSG3 DB 'Hex Number = $'
MSG4 DB 'Dec number = $'

DSEG ENDS

SSEG SEGMENT STACK 'STACK'
DW 100h DUP(?) ;steko segmentas
SSEG ENDS

CSEG SEGMENT 'CODE' ;kodo segmento pradzia

;*******************************************

START PROC FAR ;proceduros START pradzia

; issaugome grizimo adresa OS:
PUSH DS
MOV AX, 0
PUSH AX

; set segment registers:
MOV AX, DSEG
MOV DS, AX ;inicializuojame segmento regsitra DS

MOV AH,09h
MOV DX, OFFSET MSG
INT 21h
XOR AX,AX ;isvalome registra ax
MOV AH,1H ;irasome 1h i ah
INT 21H ;21h pertraukimo generavimas
MOV DL,AL ;al turini kopijuojame i dl
CMP DL,47H
JGE M3
SUB DL,30H ;apskaiciuojame skirtuma (dl)=(dl)-30h
CMP DL,9H ;lyginame (dl) su 9h
JLE M1 ;jeigu dl<=9h, persokti prie zymes M1
SUB DL,7H ;apskaiciuojame skirtuma (dl)=(dl)-7h
M1: ;zymes M1 paskelbimas
MOV CL,4H ;4h irasome i registra cl
SHL DL,CL ;registro dl turini perstumiame per 4 bitus i kaire
INT 21H
CMP AL,47H
JGE M5
SUB AL,30H ;apskaiciuojame skirtuma (al)=(al)-30h
CMP AL,9H ;lyginame (al) su 9h
JLE RESULT ;jeigu al<=9h, persokti prie zymes M2
SUB AL,7H ;apskaiciuojame skirtuma (al)=(al)-7h
RESULT: ;zymes M2 paskelbima
ADD DL,AL ;sudedame (dl)=(dl)+(al)
MOV BL,DL
MOV DH,2H ;perkeliam kursoriu i kita eilute
XOR DL,DL ;
MOV AH,02H ;
INT 10H

MOV AX, DSEG ;
MOV DS, AX ;
MOV AH,09h ; isspausdinu MSG3
MOV DX, OFFSET MSG3 ;
INT 21h ;

MOV DL,BL ;
MOV CL,4H ;
SHR DL,CL ;
CMP DL,0AH ; Pirmas skaicius
JGE RAIDE ;
ADD DL,30H ;
MOV AH,02H ;
INT 21h ;
SK2:
MOV BH,1H
MOV DL,BL ;
MOV CL,4H ;
SHL DL,CL ;
SHR DL,CL ;
CMP DL,0AH ;
JGE RAIDE ; Antras skaicius
ADD DL,30H ;
MOV AH,02H ;
INT 21h ;
JMP DEC

RAIDE:
ADD DL,37H
MOV AH,02H
INT 21h
CMP BH,1H
JNE SK2


DEC:
MOV DH,4H ;perkeliam kursoriu i kita eilute
XOR DL,DL ;
MOV AH,02H
DEC BH ;
INT 10H

MOV AX, DSEG ;
MOV DS, AX ;
MOV AH,09h ; isspausdinu MSG4
MOV DX, OFFSET MSG4 ;
INT 21h

MOV DL,BL ;
MOV CL,4H ;
SHR DL,CL ;
CMP DL,0AH ; Pirmas skaicius
JGE RAIDE2
......
;
; Here must be the code
;

ret
RAIDE2:

ADD DL,37H
MOV AH,02H
INT 21h
ret




M3:
CMP DL,60H
JLE M4
CMP DL,67H
JGE M4
SUB DL,50H ;apskaiciuojame skirtuma (dl)=(dl)-50h
CMP DL,9H ;lyginame (dl) su 9h
JLE M1 ;jeigu dl<=9h, persokti prie zymes M1
SUB DL,7H ;apskaiciuojame skirtuma (dl)=(dl)-7h
JMP M1
M4: ;ERROR spausdinimas
;perkeliu kursoriu per 2 eilutes
MOV DH,2H
XOR DL,DL
MOV AH,02H
INT 10H
; Isspausdinu teksta
MOV AX, DSEG
MOV DS, AX ;inicializuojame segmento regsitra DS
MOV AH,09h
MOV DX, OFFSET MSG2
INT 21h
RET
M5:
CMP AL,61H
JLE M4
CMP AL,67H
JGE M4
SUB AL,50H ;apskaiciuojame skirtuma (al)=(al)-30h
CMP AL,9H ;lyginame (al) su 9h
JLE RESULT ;jeigu al<=9h, persokti prie zymes M2
SUB AL,7H ;apskaiciuojame skirtuma (al)=(al)-7h
JMP RESULT



START ENDP ;proceduros START pabaiga

;*******************************************

CSEG ENDS ;kodo segmento pabaiga

END START
[/code]

Sorry for messed code

Comments

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion