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