Final Lecture Chapter 2 2 Intro To Asml Memory Segmentation
Final Lecture Chapter 2 2 Intro To Asml Memory Segmentation
– For example, the instruction MOV DX, CX copies the contents of register
CX to register DX.
– The MOV instruction does not affect the source operand.
Prepared by : Amanuel G ECE DEPARTEMENT
5
MOV instruction
– In the 8086 CPU, data can be moved among all the registers as long as the
source and destination registers match in size.
– Code such as MOV AL, DX will cause an error, since one cannot move the
contents of a 16-bit register into an 8-bit register.
– Two types of memory organizations are commonly used: linear addressing and
segmented addressing.
– The code segment contains the assembly language instructions that perform
the tasks that the program was designed to accomplish.
– Physical address is the 20-bit address that is actually put on the address pins of
the 8086 microprocessor and decoded by the memory interfacing circuitry.
– It is an actual physical location in RAM or ROM within the 1MB memory range.
– The 16-bit contents of the segment register gives the starting/base address of
a particular segment.
– The offset address is also 16-bit wide and it is provided by one of the associated
pointer or index register.
– Code Segment
To execute a program, the 8086 fetches the instructions (op-codes
and operands) from the code segment.
– Example
– The offset address is also 16-bit wide and it is provided by one of the associated
pointer or index register.
We have seen when 8-bit data is used the bytes are stored one after the another in memory. What
happens when 16-bit data is used? For example:
In cases like this, the low byte goes to the low memory location and the high byte goes to the high
memory location.
DS:1500 = F3 DS:1501 = 35
This convention is called little endian convention. All Intel microprocessors and many
microcomputers use this convention.
Although in many normal programs this segment is not used, its use is
absolutely essential for string operations.
The stack is a section of read/write memory (RAM) used by the CPU to store
information temporarily.
The CPU needs this storage area since there are only a limited number of
registers.
The two main registers used to access the stack are the SS register and the SP
register.
These registers must be loaded before any instructions accessing the stack are
used.
The storing of a CPU register in the stack is called a push, and loading the contents
of the stack into the CPU register is called a pop.
In the 8086, the stack pointer register (SP) points at the current memory location
used for the top of the stack and as data is pushed onto the stack it is decremented.
It is incremented as data is popped off the stack into the CPU.
When an instruction pushes or pops a general purpose register, it must be the entire
16-bit register. In other words, one must code “PUSH AX”; there is no instruction
such as “PUSH AL”.
To ensure that the code section and stack section of the program never write over
each other, they are located at opposite ends of the RAM memory set aside for the
program and they grow toward each other but must not meet. If they meet, the
program will crash.
As each PUSH is executed, the contents of the register are saved on the stack and SP
is decremented by 2.
With every pop, the top 2 bytes of the stack are copied to the register specified by
the instruction and the stack pointer is incremented twice.
What values are assigned to the SP and SS, and who assigns them?
– It is the job of the DOS to assign the values for the SP
and SS since memory management is the responsibility
of the operating system.