×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Segments/Offsets

Segments/Offsets

Segments/Offsets

(OP)
First off i just want to say hi to everybody! Im a Java/Visual Basic programmer of 3 years and a always wanted  to learn assembly, but im having alittle trouble understanding segments and offsets.

At the bottom is a piece of a simple Hello World prog using a86 compiler.

The way segments and offsets were explained to me was with this formula.

;OFFSET = SEGMENT * 16
;SEGMENT = OFFSET / 16 (the lower 4 bits are lost)   

From what i can gather the total number of bits with the
segment and offset combined is always 20, the Message can never be more than 2 word size(32 bits) or an error occures.

So question number one: Does the segment hold 16 bits and the offset hold 4?

Question number two: If i program with 32 bit registers can
i forgo using segments and offsets or are they always used?

Thanks for the help!


Message db "Yummy Ham!$"     ; message to be display
mov dx,OFFSET Message     ; offset of Message is in DX
mov ax,SEG Message     ; segment of Message is in AX
mov ds,ax         ; move segment of Message into a segment reg
      


  

RE: Segments/Offsets

First answer: In 16-bit programming (or even if using 32-bit registers in a 16-bit Real mode), BOTH the OFFSET and the SEGMENT are 16-bits.
What happens is that the segment is multiplied by 10h (16) and THEN the offset is added.
In 32-bit mode programming (available only in Protected Mode) the offset is 32-bits while the Segment is only a handle to the memory section it refers to, this gets pretty complicated... some OS's however make all segments start at absolute 00000000h, so that you can pretty much ignore segments.

Second answer: Depends on your MODE.  In 16-bit mode you will still use segments and offsets.  In 32-bit mode, it will depend on your OS.  Windows I think does not use segments (although other OS's might).  Note that 32-bit mode is a Protected Mode concept, if you intend to use DOS (which is Real mode and hence only supports 16-bit mode) you MUST use segments and offset (although nothing prevents you from using 32-bit registers).

In many cases you SHOULD ignore segments and pretend that you can only have offsets.  The only time you generally want to do segments is if you need to go beyond the limit, or at the start of a DOS program to set the segments properly.

Anyway the message can be up to the limit of the Offset.  In 16-bit mode, the limit of the Offset is 65535 (0ffffh) so your message can only be that number of bytes long.  In 32-bit mode the limit is somewhere in the gigabyte range, so your message can be that number of bytes long... although you'll run out of memory before that can happen.



"Information has a tendency to be free.  Which means someone will always tell you something you don't want to know."

RE: Segments/Offsets

(OP)
So when we say somthing like below. dx is just pointing to the offset of the Message? The actual offset of the message is not contained within dx? Same for ax too.  

 Message db "Hello World!$"
 Mov dx, OFFSET Message
 Mov ax, SEG Message

So "Hello World" would be 10 bits? or 2 word(16 bits)im not too sure. Some people say one and some say the other.

Thanks for the help.  

RE: Segments/Offsets

Let me put it this way.

Let's imagine you have this little nifty robot called IntelProcessor with an arm called AddressSpace which can extend and retract up to 65536 inches.  But what if you need to reach something which happens to be 65537 inches away from IntelProcessor?  Then you need to be able to move your robot's body so that it can reach the object with its AddressSpace arm.  Now, IntelProcessor does this by making use of its SegmentSystem body.  The SegmentSystem body moves by units of 16 inches so that it can reach something that is 65537, 65538 or 655360 inches away from the robot's position (which is sometimes called the ABSOLUTE ADDRESS SPACE).

So in one way of looking at things, it is 16-bit because the SegmentSystem body has been moved to with 65536 bytes of the message.  But in the ABSOLUTE ADDRESS SPACE it is 10-bits because IntelProcessor also needs to know where its SegmentSystem body is.

Or better yet, just pretend your IntelProcessor doesn't have a SegmentSystem body to move around in the ABSOLUTE ADDRESS SPACE.  Just consider it as having an AddressSpace arm that goes 65536 inches.  Besides, in Win32 segments are no longer used anyway...

"Information has a tendency to be free.  Which means someone will always tell you something you don't want to know."

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close