arhitektura 8085
DESCRIPTION
*085TRANSCRIPT
-
EE2801-L07P01
EE2801 -- Lecture 7
Assembly Languageand
Computer Organization
-
EE2801-L07P02
Assembly Programming Is A 3 Step Process
Everything in a computer system is located at some well-defined location in the memory or
the IO space of the computer.
Doing something useful with a computer involves reading data from one location, operating
on it, and storing it in another location. It really doesnt matter what the information is, or
what the desired action is, the process remains the same.
For assembly language programs, creating a program is a 3 step process:
ASCII
Source
(.asm)
Object
Files
(.obj)
Executable
(.exe)
TASM
TLINK
EDIT
TD
Assembler
Debugger
Linker
Text
Editor
-
EE2801-L07P03
Addresses - A Place For Everything
Both memory and IO are accessed using addresses. Data is sent to a memory or IO
location by to an address. Data is received from memory or IO locations by
from an address.
Portability is achieved (in part) by having rules, or standards, for how addresses are
assigned and for the behavior that is supposed to occur when addresses are accessed.
For example, the PC has a that looks something like:
writing reading
memory map
64Kb Boot
ROM
64Kb Option
ROM
128Kb Reserved
for device ROMs
128Kb Video
Memory
640Kb
Conventional
Memory
FFFFFh
F0000h
EFFFFh
E0000h
DFFFFh
C0000h
BFFFFh
A0000h
9FFFFh
00000h
-
EE2801-L07P04
Program Loading And The Operating System
Executable
(.exe)
In order to execute, somehow the executable program image must be mapped to the
memory space of the computer. In general, parts of the executable will be stored in ROM
and some in RAM. Under an operating system like Linux or Windows, the program will
load into RAM, but theres no way to tell exactly where!
It is the job of a loader to assign the image to the proper memory space(s).
640Kb
Conventional
Memory
9FFFFh
00000h
Loader
Stack
Code
Data
Note: On a PC, when a program
starts, its stack, data, and extra
segments are initialized!not
-
EE2801-L07P05
Segment-Based Addressing In The 80x86
In order to calculate a real, physical memory address the 80x86 uses a 16 bit segment
register and combines it with a 16 bit offset.
For example, consider the instruction pointer (IP). To determine the actual physical
memory location of the code, we shift the CS register left 4 bits, and add it to the IP.
Thus, if CS = A000h and IP = 27A5H then CS:IP = A27A5h as follows:
All of the segment registers in the 80x86 work this way, however the offset does not usually
come from the IP register when the DS, SS, and ES registers are used.
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0 0
0
0
0
0
0
0 0
0
0
0
0
0
0 0
0
0
0
0
0
0 0
0
0
0
0
0
CS = A000h
IP = 27A5h
CS:IP = A27A5h
Shift CS Left
-
What Segmenting Is Really Doing
EE2801-L07P06
Any segment register can hold any 16 bit value. Likewise, any 16 bit offset can be added
to any segment register. Thus, there are 65,536 possible segment locations, and each can
be thought of as a pointer to an array of 65536 memory locations
00000h
FFFFFh
64K Code
Segment
64K Extra
Segment
64K Stack
Segment
64K Data
Segment
CS
DS
SS
ES
-
Working With Segment Registers
EE2801-L07P07
Although segments and offset might sound a little confusing, there some typical ways that
segments and offsets are associated with each other, and some typical applications of the
various segments.
This register is used to find addresses for program instructions. The physical address of an
instruction is normally calculated using the IP register (CS:IP).
CS - Code Segment Register
DS - Data Segment Register
This register is used to find addresses for data items in memory. There are a number of
ways that an offset may be obtained such as direct input of a number or using the BX, DI,
or SI registers (or a combination).
The extra segment is not used very often in simple programs. When it is, it is usually
associated with string operations and the offset usually comes from the DI register.
The SP register is the most common source of an offset into the stack segment. BP is also
commonly used.
ES - Extra Segment Register
SS - Stack Segment Register
-
Keeping Track Of Segment Usage
EE2801-L07P08
Lets review the assembly language program we saw in the last lecture and think about
what the segments are doing:
Notice:
not all instructions access data from memory.
some data values are compiled in
.Data ;Create a symbolic name for the beginning of the data segment.
A db 7d ;Create a symbolic name for DS:0000 put a value there.
B db 12d ;
C db ? ;
.Code ;
start: nop ;Instruction at CS:0000
mov ax,@data ;
mov ds,ax ;
mov al,byte ptr[A] ;
mov bl,byte ptr[B] ;
add al, bl ;
mov byte ptr[C],al ;
stop: jmp stop ;
and
Create a symbolic name for DS:0001 put a value there.
Create a symbolic name for DS:0002
Create a symbolic name for the beginning of the code segment.
Instruction at CS:0001
Instruction at CS:0004
Instruction at CS:0006 gets data from location DS:0000
Instruction at CS:0009 gets data from location DS:0001
Instruction at CS:000D
Instruction at CS:000F stores data in location DS:0002
Instruction at CS:0012
and