News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

ds is not pointing to data segment, i think it has something to do with psp

Started by ggmasm32, September 16, 2015, 02:36:20 PM

Previous topic - Next topic

ggmasm32

I got following code upon compilation I call printStr function.
Inside the printStr  function, it grabs the char one by one and prints it until it meets $.
Parameters to function is ds:bp loaded with address of string with lea instruction.
However when dl is loaded with ds:[bp] it is not the string.
I can see ds has data segment address and bp is 00.

However when dumping memory, the actual data segment is at ds:200h not ds:00h. Because I can see string is located in ds:200h
I am wondering how come? If I remember vaguely it has something to do with PSP which I am refreshing my mind.
So what did I miss here? Thanks!

C:\sw.dev\exp>type asmfile.asm
.586
;.model flat, stdcall

    extrn   printf1

sta segment para stack 'stack'
    db 100h dup(0)
sta ends

data segment para public 'data'
    str0    db 'test string in asmfile.asm$'
data ends

code segment para public use16 'code'
assume cs:code, ds:data,ss:sta

main    proc    far
    mov     dl, 39h
    mov     ah, 02h
    int     21h

;   call    printf1

    lea     bp, str1
    call    printStr

    mov     ax, 4c00h
    int     21h

    main    endp

;   input
;   DS:BP   - pointer to string ($) terminated.

printStr    proc    far

printLoop:
    mov     dl, ds:[bp]
    cmp     dl, '$'
    je      quit
    mov     ah, 02h
    int     21h
    inc     bp
quit:
    ret

printStr    endp

code    ends
    end     main


Here is the memory dump and register dump during during program run:

-d ds:0
0B53:0000  CD 20 FF 9F 00 9A F0 FE-1D F0 4F 03 64 05 8A 03   . ........O.d...
0B53:0010  64 05 17 03 64 05 53 05-01 01 01 00 02 FF FF FF   d...d.S......
0B53:0020  FF FF FF FF FF FF FF FF-FF FF FF FF 11 0B 4C 01   ..............L
0B53:0030  24 0A 14 00 18 00 53 0B-FF FF FF FF 00 00 00 00   $.....S........
0B53:0040  05 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00   .......
0B53:0050  CD 21 CB 00 00 00 00 00-00 00 00 00 00 20 20 20   .!...........
0B53:0060  20 20 20 20 20 20 20 20-00 00 00 00 00 20 20 20
0B53:0070  20 20 20 20 20 20 20 20-00 00 00 00 00 00 00 00           ........
-










-d ds:200
0B53:0200  74 65 73 74 20 73 74 72-69 6E 67 20 69 6E 20 61   test string in a
0B53:0210  73 6D 66 69 6C 65 2E 61-73 6D 00 00 00 00 00 00   smfile.asm......
0B53:0220  B2 39 B4 02 CD 21 0E E8-0F 00 B8 00 4C CD 21 00   .9...!......L.!
0B53:0230  00 00 00 00 00 00 00 00-00 3E 8A 56 00 80 FA 24   .........>.V...$
0B53:0240  74 05 B4 02 CD 21 45 CB-2E 8B 5D 01 2E 8E 45 03   t....!E...]...E.
0B53:0250  43 43 2C 80 26 D7 5F 07-5B C3 50 2E 80 0E A2 90   CC,.&._.[.P....
0B53:0260  80 2E 80 26 A2 90 FD 2E-8A 04 3C 2B 74 0A 3C 2D   ...&......<+t.<-

-r
AX=0000  BX=0000  CX=0148  DX=0000  SP=0100  BP=0000  SI=0000  DI=0000
DS=0B53  ES=0B53  SS=0B63  CS=0B75  IP=0000   NV UP EI PL NZ NA PO NC
0B75:0000 B239          MOV     DL,39

dedndave

for EXE's:
CS points to entry point code segment
DS = ES point to PSP segment
SS points to stack segment

quite often, the first two lines of code are:
    mov     ax,@data      ;@data is an alias for DGROUP
    mov     ds,ax


for COM's:
CS = DS = ES = SS = PSP segment

for both EXE's and COM's:
AL = 00h, or FFh if first FCB has a file spec
AH = 00h, or FFh if second FCB has a file spec
SP points to the logical "bottom" of stack (which is mathematically the top)

i think BX has something in it too - i just don't remember what it is - lol
sorry - i am thinking of EBX for 32-bit programs   :P

dedndave

try this one...
        .MODEL  Small
        .STACK  4096
        .DOSSEG
        .386
        OPTION  CaseMap:None

;####################################################################################

        .DATA

s$Msg   db 'Hello World !',0Dh,0Ah,24h

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

        .DATA?

;####################################################################################

        .CODE

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

_main   PROC    FAR

        mov     dx,@data
        mov     ds,dx

        mov     dx,offset s$Msg
        mov     ah,9
        int     21h

        mov     ax,4C00h
        int     21h

_main   ENDP

;####################################################################################

        END     _main

dedndave


ggmasm32

thank you all, it is amazing, i need to refresh my mind on this.  :t

ggmasm32

Quote from: dedndave on September 16, 2015, 02:52:51 PM
for EXE's:
CS points to entry point code segment
DS = ES point to PSP segment
SS points to stack segment

quite often, the first two lines of code are:
    mov     ax,@data      ;@data is an alias for DGROUP
    mov     ds,ax


for COM's:
CS = DS = ES = SS = PSP segment

for both EXE's and COM's:
AL = 00h, or FFh if first FCB has a file spec
AH = 00h, or FFh if second FCB has a file spec
SP points to the logical "bottom" of stack (which is mathematically the top)

i think BX has something in it too - i just don't remember what it is - lol
sorry - i am thinking of EBX for 32-bit programs   :P

this brings old memory back. Nostalgia or dejavu? :D :D

dedndave