Transcript PSP

Chapter 2
Instruction Addressing
and Execution
Lesson plan
• Review some concepts in the first week
• First assembly program with EMU8086
• Related concepts with the first program:
– Loading program
– Boot process
– Handling the stack
Recalling main concepts
Recalling main concepts
Recalling main concepts
• Segment: special areas defined to
contain CODE, DATA and STACK
• Paragraph boundary: location
evenly divisible by 16 or 10H
Recalling main concepts
SS
DS
CS
Segment
Registers
Stack Segment
Data Segment
Code Segment
Practice
• Start EMU8086
• Type the first assembly language
given
• Compile: Compile icon
• Run:Run icon
.model small,
.stack
.data
message db "Hello everybody! I am learning assembly
language!","$"
.code
main proc
mov ax, seg message
mov ds,ax
mov ah,09
lea dx,message
int 21h
mov ax,4c00h
int 21h
main endp
end main
Result of the first program
Types of programs
• *.COM and *.EXE files
– *.COM: consists of one segment
containing code, data and stack
– *.exe: separate code, data and stack
segments
Loading *.exe program
• Access *.exe from disk
• 256-byte Program Segment Prefix (PSP)
on a paragraph boundary
• Store the program immediately
following the PSP
• Load address of PSP in the DS & ES
• Load code segment in CS, set IP
• Load address of the stack to SS, set SP
• Transfer control to the program for
execution
PSP
.model small,
.stack
.data
message db "Hello everybody! I am learning assembly
language!","$"
Assembly
directive to
.code
define
memory
main proc
model to use
mov ax, seg message
in the
mov ds,ax
program
mov ah,09
lea dx,message
int 21h
mov ax,4c00h
int 21h
main endp
end main
Real and Protected mode
16-bit
Protected
Mode
Real Mode
32-bit Protected
Mode
Segment base
20-bit
address
24-bit,
from
descriptor
32-bit,
from descriptor
Segment size
(limit)
16-bit, 64K
bytes (fixed)
16-bit, 1-64K
bytes
20-bit, 1-1M bytes or
4K-4G bytes
Segment
protection
no
yes
yes
Segment
register
segment base
address / 16
selector
selector
Protected mode
-Is a type of memory utilization, available on
Intel 80286 and later
-Support:
protection: each program is protected
from interference from other programs.
extended memory : Enables a single
program to access more than 640K of memory.
virtual memory : Expands the address
space to over 1GB.
Multitasking:
Booting process
What is booting?
• The process of starting or restarting a
computer
warm boot
cold boot
Process of turning on
a computer after it
has been powered off
completely
Process of
restarting a
computer that is
already powered on
Also called a warm
start
Booting process
How does a
personal
computer
boot up?
floppy disk drive
CD-ROM drive
CMOS
processor
hard disk
BIOS
(RAM) memory
modules
Step 6
expansion cards
BIOS Boot process
FFFF0H
Check ports
Initialize
devices
Interrupt
Vector
Table
BIOS routine
BIOS Data
Areas
Access
the bootstrap
loader
.model small,
.stack
.data
message db "Hello everybody! I am learning assembly
language!","$"
Assembly
directive to
.code
define stack
to use in the
main proc
program
mov ax, seg message
mov ds,ax
mov ah,09
lea dx,message
int 21h
mov ax,4c00h
int 21h
main endp
end main
STACK
• The word is from data structure
• Last In, First Out (LIFO)
mechanism
• STACK in OS has three main
functions:
– Contains return address
– Data
– Content of present registers
STACK
• PUSH
– Decrease SP by 2 and store a value
there
• POP
– Return a value from stack and
increase SP by 2
Lesson plan
• Review loading an *.exe file
• Concept of execution of instructions
• Practice:
• Execution of instructions
Loading *.exe file
Access *.exe from disk
256-byte Program Segment Prefix (PSP)
on a paragraph boundary
Store the program immediately
following the PSP
Load address of PSP in the DS & ES
Load code segment in CS, set IP
Load address of the stack to SS, set SP
Transfer control to the program for
execution
Loading *.exe file
• The sequence of segments (code, data,
and stack) is given
• SS: contains the address of the
beginning of the stack
• CS: contains the address of the
beginning of the code segment
• DS: contains the address of the
beginning of the data segment
• SP: contains the size of stack
Practice
2B360H
PSP
Stack Segment
Data Segment
Code Segment
Memory
Practice
2B360H
PSP
SS
2B46H
PSP
2B360H
PSP size 100H
Offset
0H
SS
2B460H
(stored as
2B46)
Stack Segment
Data Segment
Code Segment
Memory
Practice
2B360H
PSP
SS
2B46H
Stack Segment
Data Segment
CS
2B50H
Code Segment
Memory
PSP
2B360H
PSP size 100H
Offset
30H
70H
CS
2B500H
(stored as 2B50)
Practice
2B360H
PSP
SS
2B46H
2B36H
ES
2B36H
SP
0030H
Stack Segment
Data Segment
CS
DS
2B50H
Code Segment
Memory
Instruction Execution and
Addressing
• Executing an instruction include
– Fetch the next instruction, put to a
queue (QUEUE: FIFO vs. STACK LIFO)
– Decode the instruction
– Execute the instruction
Example
CS
4AF0
IP
+
0013
DS
04B1
CS segment address: 4AF00H
IP offset:
0013H
________________________
Instruction address: 4AF13H
Example
CS
4AF0
IP
0013
DS
04B1
Decode instruction:
AO: MOV [0012] to AL
4AF13H
A01200
Memory
Example
CS
4AF0
IP
0013
DS
04B1
DS segment address:04B10H
0012H
+ IP offset:
________________________
04B03H
A01200
Memory
Data address:
04B22H
Example
CS
4AF0
IP
0013
DS
04B1
Data address:
04B22
AX
04B03H
| 1B
A01200
AH
04B22H 1B
Memory
AL
Practice
• Viewing memory location using DEBUG
At DOS prompt, type: DEBUG
• Checking Serial and parallel port:
D 40:00
• Checking system equipment
D 40:10
Practice
• Viewing memory location using DEBUG
At DOS prompt, type: DEBUG
• Checking Serial and parallel port:
D 40:00
• Checking system equipment
D 40:10
reverse
22 C8
C822
Practice
• Viewing memory location using DEBUG
DOS printer
prompt,
type: DEBUG
NumberAt
of parallel
ports=11(binary)=3
(15,14)
of serial ports=100(binary)=4
(11-9) port:
•Number
Checking
Serial and parallel
Number of diskette devices=00(binary)=1 (7,6)
D 40:00
Initial video mode =10 (5,4) (80x25 color)
• Checking system equipment
Coprocessor present: 1 (1)
D 40:10
Diskette
drive is present: 0 (0)
Practice (cont.)
• Checking the keyboard status
– D 40:17 (With Numlock and Caplock)
• Checking video status
– D 40:49
– D 40:84
Practice (cont.)
• Checking copyright notice & serial
number
– D FE00:0
• Checking ROM BIOS date
D FFFF:5
Practice (cont.)
Running the first assembly program
step by step using EMU 8086