Re: Using SS for non-stack operations?




Jim Leonard wrote:
> I was reading Mark Larson's page on optimization
> (http://website.masmforum.com/mark/index.htm) and the very first entry
> is "freeing up all eight registers for use in your code". I'm
> self-taught; can someone help me understand the pros and cons of using
> SS for your own use? For example, would you use SS as a
> scratch/temporary register, or can you use it in a much more useful
> manner? And what do you run the risk of breaking (other than PUSH/POP
> of course)?
>
> My current projects are all 16-bit 8088, DOS (please, no 32-bit
> comments, my environment is fixed) and they're in desperate need of a
> third segment register as two data sources combine to affect a third.
> Currently I've tried stuff like XCHG DS,BP (but I'd really like to use
> BP as scratch if possible) and PUSH/POP DS (slow because I have to do
> this every iteration) so that's why I'm asking.
>
> (BTW, all my data sources are too large for me to fit them all into a
> single segment, so I can't use that optimization.)


Well, if you're real mode DOS, and you need an extra data segment, the
easiest thing to do is either: put your global data in your code
segment (which is read/write in real mode), or put your global area in
the same segment as your stack. Then DS and ES are free for other
purposes. So long as you can put the third area in the code or stack
segment, you all set.

If you really need three variable segments, you've got a tougher
problem. It's difficult to use SS as a scratch register in real mode,
since it's needed to handle interrupts (in protected mode an interrupt
switches to a different stack). If you can allocate a small stack
along with this third area, you can just switch the stack to that
segment, and then switch back when you're done. Alternatively, you
*can* reload SS and use it as a segment register if you disable
interrupts, but you're going to have to run disabled until you put SS
back. That will also not prevent NMIs (unless you've got hardware
generating one, it's a non-issue for most PCs) or program interrupts
(INT xx), and those will die if the happen. And, as you mentioned
you'll obviously have to avoid instructions that use the stack (intx,
bound, pushx, popx, call, ret, iret, interupts, enter, off the top of
my head). Also running disabled for too long can impact your system
negatively.

While you said 8088, if this is really a 386+ box running in real mode,
you *can* just use the extra two segment registers, even in real mode.

.



Relevant Pages

  • Re: Passing parameters from protected mode to real mode?
    ... I was wondering how parameters could be passed from pmode to real mode. ... Pmode segment shouldn't be a problem since it is set as a 4 gig segment ... I drop register values to axdata and bxdata. ...
    (comp.lang.asm.x86)
  • Re: Passing parameters from protected mode to real mode?
    ... I was wondering how parameters could be passed from pmode to real mode. ... Pmode segment shouldn't be a problem since it is set as a 4 gig segment ... I drop register values to axdata and bxdata. ...
    (comp.lang.asm.x86)
  • Re: Passing parameters from protected mode to real mode?
    ... I was wondering how parameters could be passed from pmode to real mode. ... Pmode segment shouldn't be a problem since it is set as a 4 gig segment ... Rmode addresses are 20 bits long, composed by segment register and a register or direct value, something like ds:si. ...
    (comp.lang.asm.x86)
  • x86 Assembly Language FAQ - General Part II
    ... Accessing 4 Gigs of Memory in Real Mode ... GB of memory, ... Changing the value of a segment register results in that segment's entry ... In protected mode, the value in the ...
    (comp.lang.asm.x86)
  • Frequently Asked Questions (1/6)
    ... Accessing 4 Gigs of Memory in Real Mode ... GB of memory, ... Changing the value of a segment register results in that segment's entry ...
    (comp.lang.asm.x86)