HI!
I'd like to ask you some questions about stack segments when doing dos
programming...
I know that each exe can have only one stack segment...
However...Look at this piece of code...
STACKSEG SEGMENT PARA STACK 'STACK'
DB 64 DUP(?)
STACKSEG ENDS
DTSEG SEGMENT PARA 'DATA'
VAR WORD 1444
DB 62 DUP(?)
DTSEG ENDS
CDSEG SEGMENT PARA 'CODE'
MAIN PROC FAR
ASSUME CS:CDSEG, DS:DSEG, SS:STKSEG
MOV AX, DTSEG
MOV DS, AX
MOV BX, VAR
ASSUME SS:DTSEG
MOV SS, AX
PUSH BX
MOV AH, 4CH
INT 21H
MAIN ENDP
CDSEG ENDS
END MAIN
I'm using masm for dos,and this program assembles and links without any problem.
What i've tried to do in this program,is change the SS value so that it points to dtseg instead of the "official" STACK SEGMENT.
Then,i tried to push bx,hoping that it will be stored in memory locaton DTSEG:SP.
However,when i used debug i got strange results...
I used the "trace" command...
every instruction was executing normally...
However,i reached a point where "MOV SS, AX" was about to execute...
I used again "trace"...
Normally,i should get as an output the registers' values and then next instruction that is about to execute ("PUSH BX")
Indeed,it showed me the registers' values but not the "PUSH BX" operation...
Instead of that it showed me that next instruction for execution is "MOV AH, 4CH"!
I also noticed,that the SP value had changed...Instead od the initial 40 value,3E was now in SP....
PLEASE....Does anyone know what happend here?
I'd really appreciate any help...
Thanks a lot.
law_order,
I would suggest you to read the intel docs about the x86 instructions, especially "mov ss,xx" and "push xx". All your questions should be answered there.
law_order,
Your code, as posted, will not assemble.
stack.asm(12) : error A2006: undefined symbol : DSEG
stack.asm(12) : error A2006: undefined symbol : STKSEG
stack.asm(15) : error A2074: cannot access label through segment registers
There can be only a single stack active at any one time, but a program is not limited to a single stack.
From the Intel Architecture and Programming Manual, MOV--Move data:
Quote
A MOV into SS instruction inhibits all interrupts until after the execution of the next instruction (which should be a MOV into ESP instruction).
The reason for this is that locations on the stack are specified by the
combination of SS and (E)SP. If while switching stacks, an interrupt occurred after SS was changed and before (E)SP was changed, the processor would attempt to use the stack, but the combination of the new SS and the old (E)SP would not specify a valid stack. The DEBUG trace command (AFAIK) depends on single-step mode (enabled by setting the trap flag), in which the processor generates a debug exception (Interrupt 1, also called the single-step interrupt) after each instruction. So the processor is skipping the interrupt after the MOV SS instruction, and the handler responsible for displaying the results is not called, until the next interrupt is generated after the PUSH BX instruction.
For a description of stack operation, see PUSH and POP under 3.2 INSTRUCTION REFERENCE in the Pentium Instruction Set Reference (volume 2), available here:
http://webster.cs.ucr.edu/Page_TechDocs/index.html
thanks so much guys for your replies....
everyting makes sense now...
btw...I wrote "dseg" instead of "dtseg"...i'm really sorry for the typo...