News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Displaying register values

Started by zak100, December 16, 2009, 01:50:25 PM

Previous topic - Next topic

zak100

Thanks for providing me this good explanation. Now I am trying to execute it as a standalone .com file not in conjunction with the bootsector. I am getting garbage values. I have added 4 to di also. Kindly help me in this regard. It would be really very kind of you.


.MODEL  TINY
        .CODE

;--------------------------------------------------------------------------------------

LoadOfs EQU     0                   ;must match the value in the bootloader source file

;--------------------------------------------------------------------------------------

        ORG     0

Start:  call    Push_IP             ;this CALL pushes the IP register

Push_IP:
        push    sp
        push    ss
        push    es
        push    ds
        push    cs
        push    bp
        push    si
        push    di
        push    dx
        push    cx
        push    bx
        push    ax

        mov     ax,3
        int     10h

        mov     ax,cs
        add     ax,LoadOfs/16
        mov     ds,ax

        mov     ax,0B800h
        mov     es,ax
        cld

        mov     bp,sp               ;use BP to access the stack values
        sub word ptr [bp+24],3      ;adjust for 3 byte CALL
        add word ptr [bp+22],2      ;adjust for the CALL

        mov     si,offset RegText
        mov     di,5*2*80
        mov     ah,3                ;attribute
        mov     cx,13               ;13 registers

nextreg:
        push    cx                  ;save reg-loop counter
        mov     cx,5                ;char counter for names

nextchar:
        lodsb                       ;loads AL from ds:[si]
        stosw                       ;stores AX at es:[di]
        loop    nextchar

        mov     dx,[bp]             ;get the stack value
        add di, 4                   
        ;call    B2Hex
        add     bp,2
        pop     cx                  ;reg-loop counter
        add     di,2*(80-9)         ;next line
        loop    nextreg

        mov     sp,bp               ;discard the stack values
        mov ah, 4ch
        int 21h

Halt0:  hlt
        jmp     Halt0

;--------------------------------------------------------------------------------------

HexHi   PROC    NEAR

        mov     ah,0
        shr     ax,1
        shr     ax,1
        shr     ax,1
        shr     ax,1

HexLo:: and     al,0Fh
        add     al,90h
        daa
        adc     al,40h
        daa
        mov     ah,bh
        stosw
        ret

HexHi   ENDP

;--------------------------------------------------------------------------------------

B2Hex   PROC    NEAR

;   AH = attribute
;   DX = value to display as hexadecimal
;ES:DI = video buffer address

        mov     bh,ah               ;BH = attribute
        mov     al,dh
        call    HexHi
        mov     al,dh
        call    HexLo
        mov     al,dl
        call    HexHi
        mov     al,dl
        call    HexLo
        ret

B2Hex   ENDP




Zulfi.

dedndave

all .COM (tiny model) programs must be ORG'ed at 100h
also, end the file with "END Start" to specify the entry point
those 2 changes, and it looks like it should work

EDIT - oh - one other change - comment these lines out

;        mov     ax,cs
;        add     ax,LoadOfs/16
;        mov     ds,ax

the DOS EXEC loads .COM programs with CS = DS = ES = SS
so, there is no need to set the DS register

zak100

Hi,
Thanks for your help. Its working now. I have to change:



add     di,2*(80-9)

to


add     di,2*(80-5)


Can you tell me the purpose of:


mov     ax,cs
add     ax,LoadOfs/16
mov     ds,ax



because LoadOfs=0 so ultimately, ds would get cs.

Zulfi.

dedndave

that is true, Zulfi
but, the program should be written so that changing the value of the LoadOfs EQUate will allow it to operate properly
that way, if you change the bootloader code and execute at, say, 0000:7E00, you only need to change that one EQUate
you could use a .IF structure to conditionally assemble that code
something like this should work

        .IF     LoadOfs==0
        push    cs
        pop     ds
        .ELSE
        mov     ax,cs
        add     ax,LoadOfs/16
        mov     ds,ax
        .ENDIF

zak100

Thanks.  And the LoafOfs/16 can be replaced by any other term involving LoadOfs? I mean 16 is not significant.

Zulfi.

dedndave

the /16 accounts for the fact that LoadOfs is a byte offset
we want a segment correlation, so we divide by 16
by the way, LoadOfs must be evenly divisible by 16
(the low order 4-bit nybble must always be 0)

zak100

Thanks for this. I hope I would find some eg where LoadOfs is not zero.

Zulfi.