You are on page 1of 22

Laboratory of Microprocessors

LECTURE 3

ASSEMBLY
ENG. WILSON JAVIER PEREZ HOLGUIN

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011
Program Segment Prefix (PSP)

There are basically two types of memory distribution and initial


register settings, those for -COM and those for -EXE modules.

The difference between these two is minimal really, especially when an


-EXE program is located within one physical segment (64K bytes).

The only significant difference in this instance is that when a -COM


module is loaded, all segment registers point to the start of the PSP,
while for an -EXE module, the CS register points to the start of the code
segment.

The contents of the segment registers for the simplest type of -EXE and
-COM modules is shown in the diagram here also.

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 2
Program Segment Prefix (PSP)

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 3
Program Segment Prefix (PSP)

Details the meaning of the most important fields in PSP.Offset Meaning

00h The instruction INT20h for exit to DOS; can be used for finishing a
program by passing control here; often is considered as PSP signature
(hex codes 0CDh 20h)
0Ah The full address of the exit routine address (the address of the system
routine which will gain control when the program finishes)
2Ch Segment address of the block containing the copy of the environment
area (environment variables created by the Dos command SET)
5Ch FCB blocks for two files passed as parameters; can be used as work
area
80h The length of the parameters passed in the command line (the
command tail)
81h The text of the parameters in the command line

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 4
Program Segment Prefix (PSP)

00-01H 2 Instrucción de la INT 20H para el regreso a DOS.


02-03H 2 La dirección del segmento del último párrafo de la memoria asignada.
04-09H 6 Reservado por DOS.
0A-0DH 4 Dirección de terminación. (INT 22H)
0E-11H Palabra Dirección de salida. (INT 23H)
12-15H Palabra Dirección de salida de error crítico. (INT 24H)
16-17H 2 Reservado por DOS.
18-2BH 20 Tabla de trabajo por archivo.
2C-2DH 2 Segmento del entorno del programa.
2E-31H Palabra Reservado por DOS.
32-33H 2 Longitud de la tabla de manejadores de archivos.
34-37H Palabra Apuntador a la tabla de manejadores.
38-4FH 24 Reservado por DOS.
50-51H 3 Llama la función del DOS (siempre contiene INT 21H + RETF).
52-5BH 9 Reservado por DOS.
5C-6BH 16 Estándar no abierto FCB 1.
6C-7FH 20 Estándar no abierto FCB 2.
80-FFH 128 Búfer por omisión para un DTA.

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 5
Program Segment Prefix (PSP)

The main code of a program is usually located immediately after the PSP,
which occupies 100h bytes (256 in the decimal system). DOS sets up the
DS and ES registers to point to the beginning of the PSP for all modules.
When DOS passes control to the COM-module, it sets the CS and SS
registers to the start of the PSP as well, as every part of a COM program is
located in the same segment of memory. For EXE-module, these registers
are loaded with the values assigned by the program and contained in the
module header.

The last thing that DOS does before starting the program is to pass
control to the first instruction in the program. The address of this
instruction for a COM-module is always CS:100h (256 bytes after the first
byte of the PSP). For an EXE-module, this address is again calculated
using the information from the module header.

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 6
The memory models
7

Model Data Code


Tiny* near
Small near** near
Medium near far
Compact far near
Large far far
Huge huge huge

* In the Tiny model, all four segment registers point to the same segment.

** In all models with near data pointers, SS equals DS.

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 7
.Model Syntax

.MODEL

TINY/SMALL/MEDIUM/COMPACT/LARGE/HUGE

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 8
.Model Syntax

TINY
 Code size: <=64k NEAR
 Data size: <=64k NEAR
 Code, data and stack are put into a single 64k segment.

SMALL
 Same as TINY but segments are stored separately.

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 9
.Model Syntax

MEDIUM
 Code size: any
 Data size: <=64k NEAR

COMPACT
 Code size: <=64k NEAR
 Data size: any

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 10
.Model Syntax

LARGE
 Code size: any
 Data size: any
 Arrays are accessed NEAR by high level languages and should
not be larger than 64k.

HUGE
 Same as LARGE but arrays are accessed FAR byhigh level
languages and may have any size.

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 11
.Code, .Data, and . Stack

.CODE Indicate standard code segment


.DATA Indicate standard data segment
.STACK [stack size in bytes]

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 12
What is variable

 Variable is a memory location.

 For a programmer it is much easier to have some value be


kept in a variable named "var1" then at the address
5A73:235B, especially when you have 10 or more variables.

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 13
Syntax for a variable declaration:

• name [TYPE] value

• name - can be any letter or digit combination, though it


should start with a letter. It's possible to declare unnamed
variables by not specifying the name (this variable will have
an address but no name).
• value - can be any numeric value in any supported
numbering system (hexadecimal, binary, or decimal), or "?"
symbol for variables that are not initialized.

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 14
Type ?

• TYPE :
– DB <Define Byte> 1 BYTE
– DW <Define Word> 2 BYTE
– DD <Define DoubleWord> 4 BYTE
– DF <Define FarWords> 6 BYTE
– DQ <Define QuadWord> 8 BYTE
– DT <Define TenBytes> 10 BYTE

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 15
Array

 Arrays can be seen as chains of variables. A text string is an


example of a byte array, each character is presented as an
ASCII code value (0..255).

 Can be a string

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 16
Example

Here are some array definition examples:

Data_a DB 48h, 65h, 6Ch, 6Ch, 6Fh, 00h


Data_b DB 'Hello', 0

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 17
• b is an exact copy of the a array, when compiler sees a
string inside quotes it automatically converts it to set of
bytes. This chart shows a part of the memory where these
arrays are declared:

• You can access the value of any element in array using


square brackets, for example:
MOV AL, a[3]

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 18
DUP operator

 If you need to declare variable ta large array you can use


DUP operator.

The syntax for DUP:

number DUP ( value(s) )


 number - number of duplicate to make (any constant value).
 value - expression that DUP will duplicate.

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 19
Example

• for example:
Data_c DB 5 DUP(9)
is an alternative way of declaring:
Data_c DB 9, 9, 9, 9, 9

• one more example:


Data_d DB 5 DUP(1, 2)
is an alternative way of declaring:
Data_d DB 1, 2, 1, 2, 1, 2, 1, 2, 1, 2

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 20
Constants

• Constants are just like variables, but they exist only until
your program is compiled (assembled).
• After definition of a constant its value cannot be changed.

• To define constants EQU directive is used:


name EQU < any expression >

• Example :
k EQU 5

Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 21
Where ?

Variables and constants are declared in data segment


(.DATA)

22

You might also like