0% found this document useful (0 votes)
0 views

T8U4_Memory_Model

The document outlines various memory models used in programming, including Tiny, Small, Medium, Compact, Large, and Huge, each with specific characteristics regarding code and data segment sizes and pointer lengths. It emphasizes the importance of selecting an appropriate memory model before compiling code to optimize memory usage and execution speed. Additionally, it explains how to obtain segment and offset addresses using macros in a sample C++ program.

Uploaded by

joyalprincess
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

T8U4_Memory_Model

The document outlines various memory models used in programming, including Tiny, Small, Medium, Compact, Large, and Huge, each with specific characteristics regarding code and data segment sizes and pointer lengths. It emphasizes the importance of selecting an appropriate memory model before compiling code to optimize memory usage and execution speed. Additionally, it explains how to obtain segment and offset addresses using macros in a sample C++ program.

Uploaded by

joyalprincess
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Memory Models

· The memory model sets the supportable size of code and data area.

· We need to specify an appropriate memory model before compiling and linking the source
code.

· Using memory model we can set the size limits of the data and code.

· C++ program always use different segments for code and data.

· The memory model your option for decides the default method of memory addressing , and the
default memory model is small.

Tiny : Use the tiny model when memory is at an absolute premium . All four segment registers ( CS,DS ,
ES , and SS) are intialized with the same address, and all addressing is accomplished using 16 bits .

small: All codes should fit into a single 64-KB segment , and all data should fit into a second 64-KB
segment . All pointers are 16 bits in length.Execution speed is similar to that in the tiny model.

Medium : All data should fit into single 64-KB segment . However the code is allowed to dresses. With
this the access to data is fast.However , slower program execution is observed with this model.This
model is suitable for big programs that do not store a large amount of data in memory

Compact : All codes should fit into a 64KB segment , but the data can be use multiple segments ,
However , no data item can surpass 64KB . All pointers to data are 32 bits, but jumps and calls can use
16-bit address.

Large : Both code and data are allowed to use multiple segments. All pointers are 32-BITs in length.
However , no single data item can exceed 64-KB . Code execution is slower.

Huge: Both code and data are allowed to use multiple segments. Every pointer is 32 bits in length and it
is different from large memory model only vy pointer math and not by segments.

Segments and offset Address


· Every address has two parts : segment and offset . we can separate these address parts using the
following two macros defined in dos.h header file.

· FP_SEG() - This macros is used to obtain the segment address of the given pointer varaible.

· FP_OFF() - This macro is used to obtain the offset address of the given pointer variable.

Write a program to obtain segment and offset address

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int ch;

cout<<"\n Complete address:"<<&ch;

cout<<"\n Segment address:"<<FP_SEG(&ch);

cout<<"\n Offset address:"<<FP_OFF(&ch);

getch();

OUTPUT

Complete Address: 0x8f34ff2

Segment address: 8f34

Offset address: fff2

You might also like