Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Windows API - Linking
#11
in msdos you have just 64 kb segments. How many of them has to do with which model you used to compile/assemble your program in.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#12
So when loading a real-mode assembly program, model medium, it allocates TWO 64KB segments, right? One for code and one for data. And when you use indirect addressing, it always looks in your data segment. Got it.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#13
I was not sure, so I checked:

Quote:Addresses, Pointers, Arrays and Strings - MSDOS Memory Models

On computers using the Intel 80x86 series of processors there are two different ways of storing an address. These may be called near and far . A near address requires 16 bits of storage whereas a far address requires 32 bits of storage. An actual far address is constructed from the sum of a 16 bit segment number and a 16 bit offset with a 4 bit overlap so it is effectively 28 bits long. Near addresses use less memory and can be manipulated more quickly and more simply. The use of near addresses implies a severe limitation on the amount of data a program can handle and on the amount of code that can make up the program.

C compilers intended for use in such environments often have options to generate either type of address. The selection of such options is usually controlled from the compiler command line. The choices are usually called memory models.

The Microsoft C version 5.1 compiler typically offers a choice of 5 memory models known as small, medium, compact, large and huge. Their characterisitics are summarised below.


small. This means that near addresses are used for both data objects and code objects (functions). The data and code spaces are thus restricted to 64 KByte each.

medium. Near addresses are used for data but far addresses are used for code. This restricts the data space to 64 KByte and the code space to 256 MByte. This suggests a large complex program manipulating a small amount of data.

compact. Far addresses are used for data but near addresses are used for code. This restricts the data space to 256 MByte and the code space to 64 KByte. This suggests a small simple program manipulating a massive amount of data.

large. Far addresses are used for both data and code. The data and code spaces are thus restricted to 256 MByte each. This suggests large programs manipulating large amounts of data.

huge. The ability to handle large amounts of data in the large and compact memory models suggests that the data may be stored in large aggregates or arrays. Unfortunately the large and compact models calculate addresses within data objects by adding a near offset to the base address of the object. This implies a restriction of 64 KByte on the size of a data object. This restriction is relaxed in the huge memory model which is otherwise similar to the large model.

Similar memory models are supported by Turbo C with the addition of a "tiny" model in which all the code and data occupy a single 64 KByte segment of memory.

An address, either of a data object or a function (code object) may be declared to be of other than the default type for the current memory model by using the non ANSI standard keywords near , far and huge as appropriate. A further complication concerns the standard libraries which come in different forms for each memory model. If you wish to compile a program using a particular memory model you need to have and link the set of standard libraries appropriate to that memory model. Vendors of hard disc systems love this.

The use of the "x" conversion with printf() to display pointer values is of doubtful portability. It only works when addresses consist of a single component which can be converted to an unsigned integer in a straightforward way. The ANSI standard provides the "p" conversion for use with pointers. This is specified as converting a pointer to a sequence of printable characters in an implementation defined manner.

The first program in this chapter was modified to use the "p" conversion rather than the "08x" conversion and compiled by the Turbo C compiler using the large memory model. The output produced was.


Code:
Address a = 47CA:0FFE
Address b = 47CA:0FFC
Address x = 47CA:0FF4
Address z = 47CA:0FF2


The figure before the colon (47CA) is the hexadecimal high part of the far address and the the figure after the colon is the low part of the far address.

For fuller details of memory models and associated topics you must consult your compiler manual. This section is only intended to give a flavour of what happens.

Hope this is explanatory enough Smile As you see, I was not completely accurate Tongue
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#14
Excellent. Big Grin That cleared things up tons. Big Grin
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)