LSS and sp

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
joke
Member
Member
Posts: 56
Joined: Sat Jul 22, 2006 6:20 am

LSS and sp

Post by joke »

I've just received the intel hardcopies. But I still have a real mode problem
Can anybody please help me with the LSS instruction. Suppose a real mode stack segment A (A=hexademical)

If I do mov ss,A
will the sp register automatically point to the top of ss? If not, then how can I load sp with the correct values? The intel manuals mention the LSS instruction, but how do we use it?



Thanks[/quote]
I need someone to show me the things in life that I cant find
I cant see the things that make true happiness, I must be blind
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post by JAAman »

If I do mov ss,A
you cant -- there is no mov segment, immediate
will the sp register automatically point to the top of ss? If not, then how can I load sp with the correct values?
no, SP is not altered unless you write to it, and all your writing to is SS

normally, this is done like this:
mov ax, stackSegment
mov ss,ax
mov sp,TopOfStack

the CPU will automatically block interupts for 1 instruction whenever the SS register is modified, insuring that there should never be an invalid stack, however, many people prefer to CLI first anyway, just to be certain
The intel manuals mention the LSS instruction, but how do we use it?
im not sure, never really used the LxS instructions, but it looks simple enough

create a pointer in memory (16bit selector, followed by a 16bit offset, i think), then use LSS SP, PointerToPointer
joke
Member
Member
Posts: 56
Joined: Sat Jul 22, 2006 6:20 am

Post by joke »

i'm new to asm so i don't know how to use pointers in asm

how can i make sp to point at the top of my stack?
mov ax,ss
mov sp,ax ? is this correct? :?:

thanks
I need someone to show me the things in life that I cant find
I cant see the things that make true happiness, I must be blind
SpooK
Member
Member
Posts: 260
Joined: Sun Jun 18, 2006 7:21 pm

Post by SpooK »

joke wrote:i'm new to asm so i don't know how to use pointers in asm

how can i make sp to point at the top of my stack?
mov ax,ss
mov sp,ax ? is this correct? :?:

thanks
No, using the value of SS to fill in the value for SP has no bearing... and will probably result in crashes.

The use of SS:SP combine to make the entire stack address in real mode. SS:ESP combine to make the entire stack address in protected mode (32-bit).

What you need to do, is define what the "top of the stack" is for your OS. Most people initially set it to memory locations like 000A:0000 (top of usable conventional memory) or 0000:7C00 (right under the address the MBR is loaded to). Just remember to adhere to memory segmentation while in real mode... this means that 0000:7C00 could also be 07C0:0000... and 000A:0000 would actually be A000:0000.

From there, while in Ring 0 with no multi-tasking, you should not have to change SP at all... push/pop and other stack-sensative instructions work automatically. Multi-tasking, context switching and implementing API calls all deviate from this "simplicity", but take one thing at a time ;)
Post Reply