Professional Documents
Culture Documents
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)
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)
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)
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
* In the Tiny model, all four segment registers point to the same segment.
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
Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 12
What is variable
Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 13
Syntax for a variable declaration:
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
Can be a string
Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 16
Example
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:
Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 18
DUP operator
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
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.
• Example :
k EQU 5
Electronics Engineering School – Eng. Wilson Javier Perez H Lab-uP Course - 1st semester 2011 21
Where ?
22