You are on page 1of 3

Camille C.

Malaza
BSCpE 3-2

COEN 3114
Engr. Rolito Laceda Mahaguay

MEMORY MODEL
Small
Use the small model for average size applications.
The code and data segments are different and don't overlap, so you have 64K of code and 64K of
data and stack. Near pointers are always used.
Medium
The medium model is best for large programs that don't keep much data in memory.
Far pointers are used for code but not for data. As a result, data plus stack are limited to 64K, but
code can occupy up to 1MB.
So, there you have it. In the medium model you use far pointers to access code (the code has far
call and far return instructions and manipulates with far function pointers) and you can have
multiple segments. The standard 16-bit DOS .EXE file format supports multiple segments. In the
small model all pointers are near and so you can't and don't change the default code segment in
the program.
MEMORY VARIABLE
A variable is a named object that resides in RAM memory and is capable of being examined and
modified. A variable is used to hold information critical to the operation of the embedded system.
A constant is a named object that resides in memory (usually in ROM) and is only capable of
being examined. As we saw in the last chapter a literal is the direct specification of a number
character or string. The difference between a literal and a constant is that constants are given
names so that they can be accessed more than once. For example
short MyVariable;
/* variable allows read/write access */
const short MyConstant=50; /* constant allows only read access */
#define fifty 50
void main(void){
MyVariable=50;
/* write access to the variable */
OutSDec(MyVariable); /* read access to the variable */
OutSDec(MyConstant); /* read access to the constant */
OutSDec(50);
/* "50" is a literal */
OutSDec(fifty);
/* fifty is also a literal */
}

MEMORY SEGMENTS
A segmented memory model divides the system memory into groups of independent segments
referenced by pointers located in the segment registers. Each segment is used to contain a
specific type of data. One segment is used to contain instruction codes, another segment stores
the data elements, and a third segment keeps the program stack.
In the light of the above discussion, we can specify various memory segments as:

Data segment - it is represented by .data section and the .bss. The .data section is used to
declare the memory region, where data elements are stored for the program. This section cannot
be expanded after the data elements are declared, and it remains static throughout the program.
The .bss section is also a static memory section that contains buffers for data to be declared later
in the program. This buffer memory is zero-filled.

Code segment - it is represented by .text section. This defines an area in memory that
stores the instruction codes. This is also a fixed area.
Stack - this segment contains data values passed to functions and procedures within the
program.

INTERRUPTS
Interrupts can be a scary and useful way to make your program really difficult to debug.
Interrupts are triggered by hardware events, either an I/O pin changing state or a timer timing out
and so forth. If enabled (which by default they aren=t), an interrupt causes the processor to stop
whatever it is doing and jump to a specific routine in the microcontroller called an interrupt
handler.
Interrupts are not for the faint of heart. They can be very tricky to implement properly, but at the
same time they can provide very useful functions. For example, an interrupt could be used to
buffer serial input data behind the scenes while the main PICBASIC PRO program is off doing
something else. (This particular usage would require a microcontroller with a hardware serial
port.)
There are many ways to avoid using interrupts. Quickly polling a pin or register bit instead is
usually fast enough to get the job done. Or you can check the value of an interrupt flag without
actually enabling interrupts.
However, if you just gotta do it, here are some hints on how to go about it.

The PICBASIC PRO Compiler has two different mechanisms to handle interrupts. The first is
simply to write the interrupt handler in assembler and tack it onto the front of a PBP program.
The second method is to use the PICBASIC PRO statement ON INTERRUPT. Each method
will be covered separately, after we talk about interrupts in general.
REFERENCES:
http://melabs.com/resources/pbpmanual/9_0.htm
http://www.tutorialspoint.com/assembly_programming/assembly_memory_segments.htm
http://stackoverflow.com/questions/11971579/whats-the-difference-between-the-small-memorymodel-and-the-medium-memory-model
http://users.ece.utexas.edu/~valvano/embed/chap4/chap4.htm