Calculation of 8086-segment offset

Source: Internet
Author: User
Preface

80,861 Total 20 address lines, addressing the physical address with a 16bit segment address + 4bit offset.
The same physical address can represent a test program with multiple logical addresses (different segment addresses + offsets)

Testcase1.cpp:Defines the entry point for the console application. #include "stdafx.h" #include <stdlib.h> #include <stdio.h> #include <assert.h>//Physical address based on segment and offset long

GET8086PHADDR (/*in*/int isegment,/*in*/int ioffset);

Get the Segment address int get8086segment (/*in*/long lphaddr,/*in*/int ioffset) According to the physical address and offset;

Get offset int Get8086offset (/*in*/long lphaddr,/*in*/int isegment) According to physical address and segment address;
    int main (int argc, char* argv[]) {long ltmp = 0;
    Long lphaddr = 0;
    int isegment = 0;

    int ioffset = 0;
    -D 123:456 lphaddr = Get8086phaddr (0x123, 0x456);

    printf ("0x%X = 123:456\n", lphaddr); -d?
    : 186 isegment = Get8086segment (lphaddr, 0x186);
    Ltmp = Get8086phaddr (isegment, 0x186);
    ASSERT (lphaddr = = ltmp);

    printf ("0x%X =%x:186\n", ltmp, isegment);
    -D 105:?
    Ioffset = Get8086offset (lphaddr, 0x105);
    Ltmp = Get8086phaddr (0x105, Ioffset);
    ASSERT (lphaddr = = ltmp);

  printf ("0x%X = 105:%x\n", ltmp, Ioffset);  /* Run result 0x1686 = 123:456 0x1686 = 150:186 0x1686 = 105:636 Press any key to continue ... With debug authentication, the memory results are the same in the following way, indicating that a physical address can be represented by multiple logical addresses------123:456-d 150:186-d 105:636-d 0:1686 */System ("p
    Ause ");
return 0;

} long get8086phaddr (/*in*/int isegment,/*in*/int ioffset) {return ((long) isegment << 4) + Ioffset;}

int get8086segment (/*in*/long lphaddr,/*in*/int ioffset) {return ((Lphaddr-ioffset) >> 4);}

 int Get8086offset (/*in*/long lphaddr,/*in*/int isegment) {return lphaddr-((Long) isegment << 4);}
Validation




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.