Author Topic: convert bcd numbers to ascii  (Read 17351 times)

nobody

  • Guest
convert bcd numbers to ascii
« on: April 01, 2008, 10:27:02 PM »
Hello

How can i convert bcd numbers to ascii.
Could you tell me some example.

10x

nobody

  • Guest
Re: convert bcd numbers to ascii
« Reply #1 on: April 02, 2008, 12:12:54 AM »
Treat 'em like hex!

Best,
Frank

nobody

  • Guest
Re: convert bcd numbers to ascii
« Reply #2 on: April 02, 2008, 12:25:51 PM »
coud you give me example

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: convert bcd numbers to ascii
« Reply #3 on: April 02, 2008, 03:25:53 PM »
Okay... where's your bcd? Ah, here's some! Whatever you're using for "printhex" will do...

Best,
Frank


; print time
; nasm -f bin -o myfile.com myfile.asm

org 100h

mov ah, 2 ; get rtc time
    int 1Ah

; hour in ch, minutes in cl, seconds in dh
; all in bcd

mov al, ch
    call showalhex
    mov al,':'
    int 29h
    mov al, cl
    call showalhex
    mov al, ':'
    int 29h
    mov al, dh
    call showalhex
    ret

showalhex:
    mov ah, al  ; make a copy
    shr al, 4
    call hexnyb
    mov al, ah  ; restore our value
    ; fall through
hexnyb:
    and al, 0Fh ; isolate low nibble
    add al, '0' ; convert to ascii

; this isn't going to happen with bcd!
    cmp al, '9'
    jna decdig
    add al, 7   ; adjust to 'A' - 'F'
decdig:

int 29h
    ret