Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

What to do to put segment from memory in 8086?

Status
Not open for further replies.

NTFS

Member level 3
Joined
Apr 6, 2004
Messages
67
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
576
Hi

I wrote a program for 8086.

For example in DATA SEGMENT if I want to put my data from 100H, I should use

ORG 0100H directive. But what shall I do, if I want to put my segment from some where in memory?

It is useful when we want to initialize I.V.T. (interrupt vector table). because IVT segment have to be in address of 00000h.
 

Davood Amerion

Advanced Member level 2
Joined
Mar 1, 2005
Messages
584
Helped
116
Reputation
232
Reaction score
24
Trophy points
1,298
Location
Persia
Activity points
6,351
segmentation in 8086

Just you must initialize data segment.
As i know you must put new data segment value to AX register, then mov AX register
to Data segment register.

Address calculation (EA) = (DS*16) + (general purpose register )
general purpose register is any of AX, ...DX, BP, ...
:D

Regards,
Davood
 

The Svin

Junior Member level 3
Joined
Mar 5, 2005
Messages
31
Helped
3
Reputation
6
Reaction score
0
Trophy points
1,286
Activity points
1,734
Re: segmentation in 8086

NTFS
Fisrt of all when you ask about 100h do you mean line address or offset?

ORG directive relative to so named thing "offset counter" when you write mnemonics the assembly translating those mnemincs into opcode counts their size and thus determing in what offset the current mnemonic is. It's critical for it to know 'cause when you write something like
jne @label1
if its short jcc then the opcode whould have immideat part that would be added to IP(EIP) to load diifferent value. Or if you write something like

.data
myvar dd 0
.code
mov eax,myvar
asm to make opcode that would load myvar needs to know what imm. part of opcode should be to address your myvar correctly. For this purpose offset counter (inner thing of assembler not programm) is used that counts sizes of included opcode and this way knows offset of any data label and instruction labels.
When you say ORG "number" you're CHANGING that counter forcing assembler to add to the counter "number" (and normaly you wouldn't want it, since counter calculate offset of all labels correctly without you ORGs).
for example at start of code .com file you write

@label1:
inc ax
@label2:
inc bx
each instruction whould be translated in one byte opcode
40h
43h
at the start of disk file .com byte 40h would have offset 0, and 43h would have offset 1.
And also in inner couner they would have those offsets.
so if you write
mov cl, byte ptr @label1
mov ch,byte ptr @label2
according to counter it would be the same as
mov cl,byte ptr CS:[0]
mov ch,byte ptr CS:[1]
but if you put directive
ORG 100h
it would force the couner to add 100h to address of
each instruction
so
ORG 100h
@label1:
inc ax
@label2:
inc bx
mov cl,byte ptr @label1
would mean
mov cl,byte ptr CS:[100h]
....
mov ch,byte ptr @label2
would mean
mov ch,byte ptr CS:[101h]

to address data from offset 100h
you don't need ORG directive
you just write
mov regname,byte/or word/or dword ptr DS:[100h]

in com files ORG 100h directive is used only because of the way to load com files in DOS
When DOS is loaded COM file it firstly loads at start of segment one structure called PSP (Program Segment Prefics) then (after PSP) it loaded all data (all bytes) that is in disk image of COM file.
Size of PSP is 256 bytes (100h) that's why byte in disk image file that was in the file in offset 0 becomes in offset 256h+0 (100h) in programm segement, another byte that has offset 1 in file has offset 256+1(101h) in programm segment,
... has offset n in file has offset 256+n (100h + n) in programm segment. So org 100h says asm to correct offset 'cause all those offset being loaded into memory whould be shifted by 100h.
It's only needed for com file, (ORG is used in other occasions too but I'm afraid it would be a little difficalt for you to understand in early programming)

To address some data in your programm you don't need to specify particular address, your just specify label of data or code. Asm will put correct form of address for you.
If dispite of all you need address specific particular address you just write
data(byte,word or dword) ptr DS:[address]
or if code
jmp(call,jcc) (far,near) CS:[address]

Added after 21 minutes:

Davood Amerion said:
Just you must initialize data segment.
As i know you must put new data segment value to AX register, then mov AX register
to Data segment register.

Address calculation (EA) = (DS*16) + (general purpose register )
general purpose register is any of AX, ...DX, BP, ...
:D

Regards,
Davood

It's not quite so.
1. If talking of 16bit address mode for 20bite line address it worth to say that calculation would by done by modulo 2^20
2. Not always you need to init DS. In com file OS itself load in DS correct value.
3. There are numerous ways to load DS, not only through AX register
For example you can you push\pop instructions
4. 20bit line address calculation is better spell as
[SegReg*16]+[Offset] mod 2^20
Why so?
"Cause both SegReg and offset parts can be specfied in different ways.
For example
mov cx,DS:[ebx*4][eax]
here to DS added not just value of some reg but ebx*4+eax
mov cx,DS:[01ABh]
here to DS added no regs at all - just a number 01ABh
mov cx,14:[1234]h
here is no DS or registers at all
 

Davood Amerion

Advanced Member level 2
Joined
Mar 1, 2005
Messages
584
Helped
116
Reputation
232
Reaction score
24
Trophy points
1,298
Location
Persia
Activity points
6,351
segmentation in 8086

To The Svin
before you answer or find error to any reply, it is better to read (very carfully) asked question.
 

The Svin

Junior Member level 3
Joined
Mar 5, 2005
Messages
31
Helped
3
Reputation
6
Reaction score
0
Trophy points
1,286
Activity points
1,734
Re: segmentation in 8086

Good advice! Have followed it in the very case?
Could you enlight me what's wrong in my answer?
I got it that question was about how to address something in segment (though it wasn't clear from the qeustion about what type of address is meant - and I tried to clarify it), and if there ORG directive would be usefull. Was I wrong?
I explained addressing and ORG directive.
I wonder why you don't advice me also " and know the subject"...

Added after 57 minutes:

Davood Amerion said:
Just you must initialize data segment.
As i know you must put new data segment value to AX register, then mov AX register
to Data segment register.

Address calculation (EA) = (DS*16) + (general purpose register )
general purpose register is any of AX, ...DX, BP, ...
:D

Regards,
Davood

I'll try to make my point perfectly clear.
The above is quote of your very words.
If you are wrote them then de facto you must admitt that you consider them relevant to the question.

Let us take parts of them
"Address calculation (EA) = (DS*16) + (general purpose register )"

I insist that is not right.
in 16bit mode 20bit line address calculation of DS segment formula
must look like (DS*16 + offset part) mod 20^2

In correct formula I replaced
"(general purpose register )" by "offset part"
and added mod 20^2
To understand my point we need to take in account two general ways to decode MOD/RM (part of opcode which say the processor how to calculate )
In 8086 processor there was the only one way:
In that way offset part (specified by modrm part of opcode) might be culculated as
sum of specified in it registers and number.
there might be ways:
offset = reg
offset = sum of two regs
offset = reg+num
offset = num
offset = sum of 2 regs + num

reg(s) WASN't (AREn't) ANY of GPS
you couldn't use AX, CX, DX as addressing regs!
you could one of following reg or comp of regs:
di
si
bx
bp
bx+di
bx+si
bp+di
bp+si
In this way to calc "offset part" your words about "(DS*16) + (general purpose register )" are both incompite and incorrect.
They are incomplite 'cause there are numeros ways to specify offset part in other way then just "(general purpose register )"
And they are incorrect 'cause NOT ALL of GPR could be used to calc offset part
(AX,DX,CX) can not be used.

now about mod 2^20
if you haven't got this part in formula the calculation could be wrong with some vars.
For example let's take mnemonic
mov ax,word ptr DS:[di]
let DS = F800h and di=8000h
according to your formula address would be
F800h*10h + 8000h = 100000h
that would mean that we'd got 21bit number!
In reality address would be 0. If A20 in not switched on. (and in early 8086 there was no A20!)
So your words about "carrifully reading question" has nothing to with it, 'cause all the above is about incomplitness and incorrectess in your answers, no matter to what question you are wrote them - they are just not right anyway.

Here my little son wrote for you memorizing app, so you can memories what GPR registers could be used in 8086 to calc offset part. (on your left - codes in MEM field of opcode)
You just don't know the subject, my friend :)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top