简体   繁体   中英

Size of the 8086 Code Segment

I am given the register values for CS, DS, SS, ES, SP, BP, SI, DI, AX, BX, CX, DX. How would I go about finding the size in hex bytes of the Code Segment?

You cannot.

8086 is rather outdated now, but some dynosaurus remember about it. It was a 16 bits processor but with 20 bits for the addresses : the 4 segment registers (CS, DS, ES and SS) had values shifted by 4 and the offset were added to that. The total addressable memory was 1 Mbyte.

The maximum size of any segment was 65536 bytes (0x10000). But the actual size of the code segment was not known to the processor. There was no memory protection, and it was allowed to write data in the middle of the code segment (what might be right or wrong depending if programmer knew why :-( ).

There used to be different common memory models (ref : 8086 Memory Model ):

  1. Tiny: CS = DS = SS = ES : the total program used 1 single segment and was limited to 64k bytes
  2. Small: one code segment and one data segment. Data and code both used near addressing (16 bits).
  3. Compact: one single segment for code, no limit for data : code used near addressing (16 bits), and data used far addressing(32 bits : segment + offset)
  4. Medium: one single segment for data, no limit for code
  5. Large: no limit for code and for data

So :

  • The maximum code of a segment is 64kbytes, but the used size could be less
  • the code could use as many segment as needed (for medium and large model) the size of each was less than 64k

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM