Question

A segment is only 64KB long. so a program must be maximum 64KB in size to fit into a memory segment (i.e. if the segment register value is not to be changed).

Suppose we want to write a larger than 64KB program for 8086 system. Presumably this will requires change of the segment register value somewhere in the middle of the program? Do we change it explicitly inside the program or we just write the code and let OS handle it? How would OS like DOS handle such larger program?

Was it helpful?

Solution

x86 processors have variants of JMP and CALL where you specify a new value for CS (the code segment register). This is known as a far JMP/CALL, and the exact syntax differs between different assemblers. If we use NASM as an example, you'd write:

; Do an inter-segment jump to the label named foobar
jmp (seg foobar):foobar

; Do an inter-segment call to the subroutine named foobar
call (seg foobar):foobar

There might be assemblers that are smart enough to figure out to generate a far jump even if you just wrote jmp foobar and foobar is located in a different segment, though I can't name any examples since this isn't something I've tested.

OTHER TIPS

If your program will be compiled to a .com file, your code cannot be larger than ~63 KB. If you want to add code, you have to write that code to a separate file and to load the code from the file during runtime. To create arrays or add code or data outside of the segment where the .com file has been loaded to, your program has to reserve free memory. To do this, use the DOS function to reserve free space. Before doing this, use the DOS function to give back the whole memory that is used by your program except the current segment.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top