Thread: Access contents of pre-specified memory address

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    23

    Access contents of pre-specified memory address

    Hello, I am attempting to write some code to be executed in MS-DOS that will copy data from the 0xC000 segment into the 0x8000 segment (this has to do with the video bios).

    My problem is that I can not figure out how to access the contents of a specific memory address. From what I have been reading this can be done is DOS, obviously not in windows though.

    I see that 'far pointers' will be needed to accomplish this since the data are in two different segments (the memory is represented as segment: offset), but can't seem to even be able to write code that will read the contents of a specified memory address and display them in a printf statement.

    For example, can anyone show me how to access the contents of memory address 0xC0000000 and print the contents out in a printf statement?

    Any help is greatly appreciated.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    DOS compilers usually had some kind of MKFP macro to make a far pointer for you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    23
    i found the macro in the dos.h file but i don't know how to use it.

    #define _MK_FP(seg, offset) (void __far *)(((unsigned long)seg << 16) \
    + (unsigned long)(unsigned)offset)

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Like
    void *p = _MK_FP(0xc000,0x0000)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jun 2010
    Posts
    23
    ok thanks, i figured that part out. now for the second part. how do i change the INT10 vector to point to 8000h segment?

  6. #6
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by pole1080 View Post
    ok thanks, i figured that part out. now for the second part. how do i change the INT10 vector to point to 8000h segment?
    In <dos.h> there's a union struct called REGS. Create a variable of that type, initialize its member ax to to 0x8000. Now invoke the BIOS services thro' int86() with 0x10 as its first argument.
    Last edited by itCbitC; 06-08-2010 at 03:33 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointers
    By chadmandoo in forum C++ Programming
    Replies: 6
    Last Post: 11-23-2008, 12:40 PM
  2. Replies: 10
    Last Post: 09-04-2008, 01:27 PM
  3. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  4. Pointer to specific memory address
    By elnerdo in forum C++ Programming
    Replies: 10
    Last Post: 05-19-2006, 07:35 AM
  5. pointerz
    By xlordt in forum C Programming
    Replies: 6
    Last Post: 01-11-2002, 08:31 PM

Tags for this Thread