x86 and Segments

Started by
6 comments, last by Dim_Yimma_H 19 years, 4 months ago
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)

        .FARDATA

SEGMENT MyData
    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
ENDS
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.
Advertisement
Not sure, but shouldn't you use LEA?
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/
-
+click here to veiw sig
+My Myspace
+[email=webmaster@hideoutgear.com]Email Me[/email]
Quote: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!
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, 7CodeStart:	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	MOV DL, AL	MOV AH, 2	INT 21H	;exit program	MOV AH, 4Ch	INT 21h


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

\Jimmy H
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 =)
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.

Regards,
Pat.
Instead of this:
LEA BX, someData
you could write like this:
MOV BX, OFFSET someData
I've actually heard that the later one is supposed to be faster, I'm not sure though.

\Jimmy H

This topic is closed to new replies.

Advertisement