Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why my program jmp to 0100:0012 ? 1

Status
Not open for further replies.

maxcai

Programmer
Aug 17, 2003
5
CN
;=================================
stacksg segment para stack 'stack'
dw 13 dup(0)
stacksg ends
;=================================
datasg segment 'data'
fldb dw 123H
datasg ends
;=================================
codesg segment 'code'
main proc far
assume cs:codesg,ds:datasg,ss:stacksg
mov ax, datasg
mov ds, ax

xor ax , ax
mov cx ,12
initial:
push ax
inc ax
loop initial

mov cx , 12
read:
pop bx
mov dl , bl
mov ah , 02H
int 21H
loop read

mov ax , 4c00H
int 21H
main endp
codesg ends
end main
It come out with error,so I use debug to trace it
-t

AX=1510 BX=0000 CX=004F DX=0000 SP=001A BP=0000 SI=0000 DI=0000
DS=14FE ES=14FE SS=150E CS=1511 IP=0003 NV UP EI PL NZ NA PO NC
1511:0003 8ED8 MOV DS,AX
-t

AX=1510 BX=0000 CX=004F DX=0000 SP=001A BP=0000 SI=0000 DI=0000
DS=1510 ES=14FE SS=150E CS=1511 IP=0005 NV UP EI PL NZ NA PO NC
1511:0005 33C0 XOR AX,AX
-t

AX=0000 BX=0000 CX=004F DX=0000 SP=001A BP=0000 SI=0000 DI=0000
DS=1510 ES=14FE SS=150E CS=1511 IP=0007 NV UP EI PL ZR NA PE NC
1511:0007 B90C00 MOV CX,000C
-t

AX=0000 BX=0000 CX=000C DX=0000 SP=001A BP=0000 SI=0000 DI=0000
DS=1510 ES=14FE SS=150E CS=1511 IP=000A NV UP EI PL ZR NA PE NC
1511:000A 50 PUSH AX
-t

AX=0000 BX=0000 CX=000C DX=0000 SP=0018 BP=0000 SI=0000 DI=0000
DS=1510 ES=14FE SS=150E CS=1511 IP=000B NV UP EI PL ZR NA PE NC
1511:000B 40 INC AX
-t

AX=0001 BX=0000 CX=000C DX=0000 SP=0018 BP=0000 SI=0000 DI=0000
DS=1510 ES=14FE SS=150E CS=1511 IP=000C NV UP EI PL NZ NA PO NC
1511:000C E2FC LOOP 000A
-p

AX=000C BX=0000 CX=0000 DX=0000 SP=0002 BP=0000 SI=0000 DI=0000
DS=1510 ES=14FE SS=150E CS=1511 IP=000E NV UP DI PL NZ NA PO NC
1511:000E B90C00 MOV CX,000C
-t

AX=000C BX=0000 CX=000C DX=0000 SP=0002 BP=0000 SI=0000 DI=0000
DS=1510 ES=14FE SS=150E CS=1511 IP=0011 NV UP DI PL NZ NA PO NC
1511:0011 5B POP BX
-t

AX=000C BX=000B CX=000C DX=0000 SP=0004 BP=0000 SI=0000 DI=0000
DS=1510 ES=14FE SS=150E CS=0100 IP=0012 NV UP DI PL NZ NA PO CY
0100:0012 0000 ADD [BX+SI],AL DS:000B=00
-t

AX=000C BX=000B CX=000C DX=0000 SP=0004 BP=0000 SI=0000 DI=0000
DS=1510 ES=14FE SS=150E CS=0100 IP=0014 NV UP DI PL NZ NA PO CY
0100:0014 0000 ADD [BX+SI],AL DS:000B=0C

Why is there is add instruction, and the cs become 0100 ,which is out of the scope of my program?

regards,
Max
 
Max,

This is my first suspect. In your code:

initial:
push ax
inc ax
loop initial


It push'ed the AX value for every loop. So when it pop'ed into BX, your stack is pointing to the last AX value. Try to move "push ax" before the "initial" label

push ax
initial:
inc ax
loop initial

Hope it helps

-- AirCon --
 
Sorry, I didn't read your message carefully. Please ignore my first replied.

Your problem is your stack is not big enough. Try to increase the stack


stacksg segment para stack 'stack'
dw 15 dup(0)
stacksg ends


Hope it works

-- AirCon --
 
Hello AirCon.
I change the stack to dw 14 dup(0).And it woks.
I'm puzzled that I just pop 12 word to the stack, but I have at leat 14-word stack. Can you explain why?
 
I'm not exactly sure myself. But I think it must have at least 2 more stacks left to save CS value internally.

I'm curious about why you use push and pop to get the value from 11 to 0. Why not just use temporary variable or register ?


-- AirCon --
 
I'm studying the action of the stack.
By the way, the program use the 12-word stack works in the pure dos 7.1 and command in the windows 2003 , but not in the command of win98. I think the problem is the about the virtual dos in windows.
I wonder how these dos manage the stack.
 
Yep, you right. I got error too in WinME dos command. Well I have no idea why. Hope someone knows the answer

Good luck with your study :)
Regards

-- AirCon --
 
The problem is probably this:

You have called int 021h within the 2nd loop.
an interrupt call is a far call saving the flags before it goes, so you need 3 words of space on the stack to make int 021h work (you need space on the stack to save the return address in far form and the flags). At the point you first call int 021h you've just popped the first of 12 words, so you have 11 words on the stack. Therefore (in theory) you need a stack of 11+3 words to make your program work.

Something I'm not sure about is whether you ought to provide dos with any stack space. It actually has its own stacks, so probably not.

If you overshoot your stack, because you are in assembler, there is no particular safety net. What happens depends on the operating system and what chances to be in the memory location you overshoot to. If it's outside the memory allocated to your program, and you're in a protected mode system, you will get a strong objection from the operating system, which will close your program. Otherwise, you may get away with it, or not, depending on whether overwriting that memory causes problems to your program or any vital bit of the dos box. If the program works, it's by accident, not design.

Hope that helps.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top