Jump to content
  • Advertisement
Sign in to follow this  

x86 and Segments

This topic is 5047 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm building an x86 app and I'd like to create and use my own memory segments. I've done a good bit of this with the SEGMENT keyword, but even though I (think) I've defined the segment, I'm not able to get the data out of it. =\ I'm hoping someone can tell me how to do this. So, if I do this (note that the data is arbitrary just for example)

    someData    DB 0
                DB 1
                DB ... LOTS MORE DATA
                DB 9999 ; LAST ONE

    otherData   DB 9999
                DB 9998
                DB 9997 ETC LOTS MORE...
                DB 1
How do I access someData or otherData? I figured this would do it...
    PUSH    SEGMENT MyData     ; move the segment address into ES
    POP     ES

    MOV     SI, OFFSET someData; now where in that segment address?     

    MOV     AX, [ES:SI]        ; move first byte into AX...

but this doesn't work. And I tried MOVing 0 *and* OFFSET MyData into SI, and I got the *exact* same result every time...the result being that I seem to start looking at my data midway in. Does *anybody* remember this stuff? I've been scouring the web with google and I've yet to find any documentation that really clarifies how this works.

Share this post

Link to post
Share on other sites
Original post by Adam Gleason
I wish i could help man but if you guys want to join my Newbie C++ study group that would be awsome go to http://newbiegroup500.tripod.com/
You really shouldn't derail or attempt to hijack other people's threads. Consider this a friendly warning, as I recognize you're new here. It's simply not polite. If you have nothing to add to the topical conversation, move on to another thread.

Edit: Alternately, you could put a small blurb in your signature (go into your control panel), so that you advertise without the above infraction. Be subtle!

Share this post

Link to post
Share on other sites
I'm not used to using the SEGMENT keyword but here's how I use to access data segments:

jmp CodeStart
;some data segments with digits

someData DB 0, 1, 9
otherData DB 9, 8, 7


LEA BX, someData ;retrieve address of someData segment
ADD BX, 2 ;2 bytes offset to address to get "9"

MOV AL, [BX] ;move the byte at address in BX to AL

;make the digit into ASCII and send
;an interrupt to display it

ADD AL, 48


;exit program

INT 21h

Sorry if I misunderstood the segment you were trying to use.

\Jimmy H

Share this post

Link to post
Share on other sites
I've never even seen or heard of the LEA instruction before. I'm writing code for a (brace yourselves) 486 machine...is the LEA instruction for more modern architectures or is it a standard...and what's it do?

I'll google it, like everything else...but like everything else, people are still smarter than google =)

Share this post

Link to post
Share on other sites
LEA (Load Effective Address) is present since the first x86. You can play nice tricks with it on a 486 since it can even be used to perform integer arithmetics (virtually for free since it is implemented on a different processor unit - AGU [Address Generation Unit), not the ALU [Arithmetic Logic(?)]).

The whole (IMHO totally bloated) CISC architecture might have many more or less useful instructions you might not know about, but LEA is a pretty basic and essential one.


Share this post

Link to post
Share on other sites
Instead of this:
LEA BX, someData
you could write like this:
I've actually heard that the later one is supposed to be faster, I'm not sure though.

\Jimmy H

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!