flat assembler
Message board for the users of flat assembler.

Index > DOS > Displaying 16-bit Registers in Hex

Author
Thread Post new topic Reply to topic
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie 01 Aug 2013, 15:04
I developed a macro to display/print the true HEX value of one register at a time so that I can see the immediate effect of my code. It is to be used in COM format.

Code:
org 100h
hextab db '0123456789ABCDEF'
macro prtReg a
{
        local .go, .done

        pusha
        push a
        mov bx, hextab

        mov cx, a
        xor si, si
        xchg ch, cl ;process MSB first

        .go:
        mov dl, cl
        and cl, 0Fh   ;extract nibble
        and dl, 0F0h  ;extract nibble and
        shr dl, 4     ;shift to lowest nybble
        ;Digit Translations
        mov al, dl
        xlat [bx]
        prtChar al
        mov al, cl
        xlat [bx]
        prtChar al
        inc si
        cmp si, 2
        je .done
        pop a      ;process the other half
        mov cx, a
        jmp .go

        .done:
        prtChar 'H'
        popa
}
macro prtChar a
{
     ;BIOS: Prints a character
     push ax
     mov ah, 0eh
     mov al, a
     int 10h
     pop ax
}
macro pquit
{
        mov ah,0h
        int 16h
        int 20h
}

prtReg si  ;problem buddy?
pquit    


My problems are;

1. The NTVDM (Win8) complains every time I try to print SI or CS. No problem with other registers. I debugged it with the debug command and found nothing wrong with it.

2. Is there any trick to get the value of IP?

Thank you in advance for your help.
Post 01 Aug 2013, 15:04
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie 01 Aug 2013, 15:33
Sample usage is:

Code:
mov bp, 16o
prtReg bp ;prints in HEX    


The only problem is with SI. I suspect this has something to do with xor si, si instruction I used. But I already pushed and popped it properly. That doesn't happen with DI.
Post 01 Aug 2013, 15:33
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1625
Location: Toronto, Canada
AsmGuru62 01 Aug 2013, 16:17
SI is used to do work, yet you do "pop a" and it turns into "pop si" as per macro replacement of parameters.
Post 01 Aug 2013, 16:17
View user's profile Send private message Send e-mail Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie 01 Aug 2013, 16:27
AsmGuru62 wrote:
SI is used to do work, yet you do "pop a" and it turns into "pop si" as per macro replacement of parameters.


Did you mean I aliased it? I thought that a param is supposed to be a variable or a constant and that pusha should be enough in reserving si.
Post 01 Aug 2013, 16:27
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie 01 Aug 2013, 16:53
Ok I got it Guru... just some minor changes.

Code:
org 100h
hextab db '0123456789ABCDEF'
macro prtReg a
{
        local .go, .done

        pusha
        ;push a
        mov bx, hextab ;for XLAT

        mov cx, a
        xor si, si
        xchg ch, cl

        .go:
        mov dl, cl
        mov dh, ch ;updated
        and cl, 0Fh   
        and dl, 0F0h 
        shr dl, 4     
        ;Digit Translations
        mov al, dl
        xlat [bx]
        prtChar al
        mov al, cl
        xlat [bx]
        prtChar al
        inc si
        cmp si, 2
        je .done
        ;pop a      
        mov cl, dh ;updated
        ;mov cx, a
        jmp .go

        .done:
        prtChar 'H'
        popa
}
macro prtChar a
{
     ;BIOS: Prints a character
     push ax
     mov ah, 0eh
     mov al, a
     int 10h
     pop ax
}
macro pquit
{
        mov ah,0h
        int 16h
        int 20h
}
;Sample usage
mov si, 4
shr si, 1
prtReg si  ;problem solved. Thanks to Guru Very Happy
pquit    
Post 01 Aug 2013, 16:53
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 01 Aug 2013, 22:13
fasmnewbie wrote:
2. Is there any trick to get the value of IP?
Use call instruction.

You may add if ~ a eq al around mov al, a inside prtChar macro to avoid otherwise perfect nop in form of mov al, al. Another improvement may be using eqtype operator to merge mov ah/al, imm8 into mov ax, imm16 for literal numeric/character argument.

There is (slow, rarely used, and unavailable in 64-bit mode) aam 16 instruction that can be used to split al into nibbles.
Post 01 Aug 2013, 22:13
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie 29 Oct 2013, 15:51
baldr wrote:
fasmnewbie wrote:
2. Is there any trick to get the value of IP?
Use call instruction.

You may add if ~ a eq al around mov al, a inside prtChar macro to avoid otherwise perfect nop in form of mov al, al. Another improvement may be using eqtype operator to merge mov ah/al, imm8 into mov ax, imm16 for literal numeric/character argument.

There is (slow, rarely used, and unavailable in 64-bit mode) aam 16 instruction that can be used to split al into nibbles.


Thanks for the trick and advice.
Post 29 Oct 2013, 15:51
View user's profile Send private message Visit poster's website Reply with quote
jamespond



Joined: 07 Nov 2013
Posts: 1
jamespond 08 Nov 2013, 16:43
My "reg to text display" routine shows dl reg as text. It called two times:
.
.
table db "0123456789abcdef"
.
push dx
mov dl,dh
call hexout
pop dx
call hexout
.
.

hexout: mov al, dl
lea bx, table
shr al, 4
xlat
mov ah, 0eh
int 10h
mov al, dl
and al, 0fh
xlat
mov ah, 0eh
int 10h
ret
Post 08 Nov 2013, 16:43
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.