News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

A problem with SEG directive

Started by Zest, October 23, 2006, 10:35:42 PM

Previous topic - Next topic

Zest

Hi,
I was checking some snippet of codes in AOA book.
Then I faced this part:

mov ax, offset yyyy ;Pass this parameter by ref
mov word ptr Ref1Proc1, ax
mov ax, seg yyyy
mov word ptr Ref1Proc1+2, ax
call ThisProc


As this part was coded in 16 bits segmented model and the address of this type codes can't comply with flat model(as they need  32 bit registers to maintain 32 bit addresses ) I changed this program to this one to check the behaviour of the code:

.DATA
    Ref DWORD 5 DUP(?)

new SEGMENT PARA PUBLIC
     uNtx DWORD ?
new ENDS

.CODE
     mov eax,OFFSET uNtx
     mov DWORD PTR Ref,eax
     mov ESI,SEG uNtx


But the last line gives me an error of this like:

Quote--------------------Configuration: Struct - Debug--------------------
Assembling: ..\Struct.asm
..\Struct.asm(80) : error A2004: symbol type conflict
Struct.obj - 1 error(s), 0 warning(s)


Could you tell me how you use SEG directive in programming?
Please make an example.

I also on Page 587 saw this example:

xyz_i equ 8[bp]


mov bx, xyz_i ;Get ptr to I
mov [bx], cx ;Store result away.


Trying to assemble these lines I got an error by the last instruction.

mov [bx], cx

It surely makes an error.
I don't know how this instrction is possible to use in coding.
At the first line it puts the value in stack into bx and then the value in cx is copied to bx while the derefrencing instruction is used.
You see that in this snippet of code bx is not pointing to anything,so how the derefrencing instrction is used and how is this instruction valid?
I have become a bit confused.

Please crarify this problem.

Thanks in advance.
Best Regards,
Zest.


















hutch--

Zest,

Please post 16 bit DOS question in the 16 bit forum, the rest are for 32 bit code.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

japheth

Hi,

> Could you tell me how you use SEG directive in programming?

the SEG directive only works if output is to be in OMF format, COFF cannot handle segments.
If you are using MASM version >= 7, you must add the "/omf" option to the cmdline

-------------------------------------------------------------------------------------

> It surely makes an error.
> I don't know how this instrction is possible to use in coding.

the code

mov bx,8[bp]
mov [bx], cx

is no problem at all if "8[bp]" is a pointer to a variable of (at least) WORD size


Zest

Hi,
Thanks for the reply but,it's a bit strange for me to put an address of a pointer on stack.
because the code you see here,there are these instruction s:

push bp
mov bp,sp

Then you have this code:

mov bx,8[bp]      ;in fact,it's [bp+8]
mov [bx], cx

Normally,at address [bp+8] should be a value that the first instruction wants to fetch.

That's why I think the second instruction makes a FATAL ERROR.

Regards,
Zest.


MichaelW

The second instruction will cause an exception if [bp+8] is not a valid "pointer to a variable of (at least) WORD size".
eschew obfuscation