flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Linux > hello! about linux fasm segment address a problem

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
kerr



Joined: 24 Feb 2016
Posts: 118
hello! about linux fasm segment address a problem
Do you know how FASM will move the segment address to DS or CS?


Eg:MASM

Code:

data segment
msg 'hello world'
data ends
mov ax,data
mov ds,ax




Eg: Fasm

Code:

segment readable writeable
msg 'hello world!'
segment executable
mov ax????



[/quote]

_________________
I hope we will be good friends.
Post 02 Apr 2016, 00:54
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14795
Location: Lost in translation
I didn't realise Linux supported 16-bit code.

What is in your "format ..." line?
Post 02 Apr 2016, 01:04
View user's profile Send private message Visit poster's website Reply with quote
system error



Joined: 01 Sep 2013
Posts: 477
mr kerr, I suggest you stop reading 16-bit examples (int 21h, cs, ds etc) because you'll be confusing yourself. We will sue you if you keep reading them and then trying to implement them on 32-bit Linux. Yeahhh!
Post 02 Apr 2016, 01:32
View user's profile Send private message Reply with quote
kerr



Joined: 24 Feb 2016
Posts: 118
Re: hello! about linux fasm segment address a problem

kerr wrote:
Do you know how FASM will move the segment address to DS or CS?


Eg:MASM

Code:

data segment
msg 'hello world'
data ends
mov ax,data
mov ds,ax




Eg: Fasm

Code:

segment readable writeable
msg 'hello world!'
segment executable
mov ax????




[/quote]


I is want speak fasm How to take the segment address move to ds segment?

_________________
I hope we will be good friends.
Post 02 Apr 2016, 23:32
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14795
Location: Lost in translation
kerr: What is your format?

Code:
format ...   ;<--- what do you have here?

Post 03 Apr 2016, 00:38
View user's profile Send private message Visit poster's website Reply with quote
kerr



Joined: 24 Feb 2016
Posts: 118

revolution wrote:
kerr: What is your format?

Code:
format ...   ;<--- what do you have here?



is use ld -m elf_i386 -Ttext 0x10000

you know fasm use segment address move to ds register?

_________________
I hope we will be good friends.
Post 05 Apr 2016, 09:34
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14795
Location: Lost in translation
kerr: Do you have a line in your source "format ..."? I ask because there is no ELF format that supports 16-bit code.

And if you are using 32-bit mode then there are no segments in 32-bit mode. 32-bit mode has selectors which you can't (or at least shouldn't try to) change from user code.


Last edited by revolution on 05 Apr 2016, 15:05; edited 2 times in total
Post 05 Apr 2016, 13:21
View user's profile Send private message Visit poster's website Reply with quote
system error



Joined: 01 Sep 2013
Posts: 477
mr kerrrrrrrrr,

You mixed up too many things that are not even compatible with each other.

You are referring to 16-bit MASM code that don't even compile in Linux. MASM sticks with Windows-only. Then I suspect you are referring to 16-bit NASM code that use ld as linker on Linux or Windows or probably both.

If you want to learn FASM 16-bit program, use Windows, don't use Linux. I give you one code template that you can use to start programming 16-bit FASM


Code:
format MZ
entry CSEG:main

segment DSEG
msg db 'Hello World',0dh,0ah,'$'

segment CSEG
main:

mov ax,DSEG
mov ds,ax
mov dx,msg
mov ah,9
int 21h

mov ah,4ch
int 21h 



Now you can start practicing your 16-bit code. Come back if you still have problems. I haven't tested this code but I think they should run (you have 32-bit Windows, right?)
Post 05 Apr 2016, 14:29
View user's profile Send private message Reply with quote
kerr



Joined: 24 Feb 2016
Posts: 118

revolution wrote:
kerr: Do you have a line in your source "format ..."? I ask because there is no ELF format that supports 16-bit code.

And if you are using 32-bit mode then there are no segments in 32-bit mode. 32-bit mode has selectors which you can't (or at least shouldn't try to) change from user code.




You Misunderstanding my meaning!

iI Just want Ask fasm move segment address!

_________________
I hope we will be good friends.
Post 06 Apr 2016, 01:07
View user's profile Send private message Reply with quote
kerr



Joined: 24 Feb 2016
Posts: 118

system error wrote:
mr kerrrrrrrrr,

You mixed up too many things that are not even compatible with each other.

You are referring to 16-bit MASM code that don't even compile in Linux. MASM sticks with Windows-only. Then I suspect you are referring to 16-bit NASM code that use ld as linker on Linux or Windows or probably both.

If you want to learn FASM 16-bit program, use Windows, don't use Linux. I give you one code template that you can use to start programming 16-bit FASM


Code:
format MZ
entry CSEG:main

segment DSEG
msg db 'Hello World',0dh,0ah,'$'

segment CSEG
main:

mov ax,DSEG
mov ds,ax
mov dx,msg
mov ah,9
int 21h

mov ah,4ch
int 21h 



Now you can start practicing your 16-bit code. Come back if you still have problems. I haven't tested this code but I think they should run (you have 32-bit Windows, right?)



I just Want ask linux for fasm move segment address ! With this Independent!

_________________
I hope we will be good friends.
Post 06 Apr 2016, 01:09
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14795
Location: Lost in translation
kerr: You misunderstand the Linux system. It doesn't have segments. It has selectors, and you have no control over them from the source code, and thus you can't give them a name and set them to whatever you want.

You can always access the DS (or CS, or whatever) register, that is trivial, but it is not a segment. All OSes that use protected mode do not have segments. So you are asking for something that does not exist.
Post 06 Apr 2016, 01:14
View user's profile Send private message Visit poster's website Reply with quote
kerr



Joined: 24 Feb 2016
Posts: 118

revolution wrote:
kerr: You misunderstand the Linux system. It doesn't have segments. It has selectors, and you have no control over them from the source code, and thus you can't give them a name and set them to whatever you want.

You can always access the DS (or CS, or whatever) register, that is trivial, but it is not a segment. All OSes that use protected mode do not have segments. So you are asking for something that does not exist.



oh yeah! Even if you're right, I wont do it.
because if computer it doesn't have segments how to run your program?

objdump eg:

Code:

$ objdump -d -j .plt libfoobar.so  

libfoobar.so:     file format elf32-i386 

Disassembly of section .plt

000003a4 <__gmon_start__@plt-0x10>: 
 3a4:   ff b3 04 00 00 00       pushl  0x4(%ebx
 3aa:   ff a3 08 00 00 00       jmp    *0x8(%ebx
 3b0:   00 00                   add    %al,(%eax
        ... 

000003b4 <__gmon_start__@plt>: 
 3b4:   ff a3 0c 00 00 00       jmp    *0xc(%ebx
 3ba:   68 00 00 00 00          push   $0x0 
 3bf:   e9 e0 ff ff ff          jmp    3a4 <_init+0x18

000003c4 <cos@plt>: 
 3c4:   ff a3 10 00 00 00       jmp    *0x10(%ebx
 3ca:   68 08 00 00 00          push   $0x8 
 3cf:   e9 d0 ff ff ff          jmp    3a4 <_init+0x18

000003d4 <fwrite@plt>: 
 3d4:   ff a3 14 00 00 00       jmp    *0x14(%ebx
 3da:   68 10 00 00 00          push   $0x10 
 3df:   e9 c0 ff ff ff          jmp    3a4 <_init+0x18

000003e4 <fprintf@plt>: 
 3e4:   ff a3 18 00 00 00       jmp    *0x18(%ebx
 3ea:   68 18 00 00 00          push   $0x18 
 3ef:   e9 b0 ff ff ff          jmp    3a4 <_init+0x18

000003f4 <__cxa_finalize@plt>: 
 3f4:   ff a3 1c 00 00 00       jmp    *0x1c(%ebx
 3fa:   68 20 00 00 00          push   $0x20 
 3ff:   e9 a0 ff ff ff          jmp    3a4 <_init+0x18




readelf eg:

Code:

$ readelf -r bar.o  

Relocation section '.rel.text' at offset 0x4bc contains 6 entries:
 Offset     Info    Type            Sym.Value  Sym. Name 
00000008  00000b02 R_386_PC32        00000000   __i686.get_pc_thunk.bx
0000000e  00000c0a R_386_GOTPC       00000000   _GLOBAL_OFFSET_TABLE_
00000025  00000d04 R_386_PLT32       00000000   cos
0000002e  00000e03 R_386_GOT32       00000000   stdout
00000044  00000509 R_386_GOTOFF      00000000   .rodata
00000050  00000f04 R_386_PLT32       00000000   fprintf





I just want ask use fasm how to move the program head address to ds segments.

if use ld linker eg:

Code:

format elf
public _start
section ".data" readable writeable
msg db "hello world!",0xa

section ".text" executable

_start:
mov eaxdata
mov dseax
mov eax,msg
……
……

$ fasm hello.asm
$ ld -s hello.o -o hello




if no use linker fasm is no segment mark, I don't know how to move the segment address to ds register!


Code:

format elf executable
entry _start

segment readable writeable
msg db "hello world!",0xa
segment executable
_start
 mov eax,???
 mov ds,eax
 mov eax,msg
……
……

$ fasm hello.asm




what do you know my say?

_________________
I hope we will be good friends.
Post 06 Apr 2016, 17:12
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14795
Location: Lost in translation
kerr: fasm doesn't move the segment address to DS because there are no segment address registers in 32-bit protected mode. DS is a selector and it does not correspond to any address directly. The OS assigns the values for the selectors and user code can't control that. You simply do not need to change the value of any of the CS, DS, ..., SS registers.
Post 06 Apr 2016, 23:43
View user's profile Send private message Visit poster's website Reply with quote
kerr



Joined: 24 Feb 2016
Posts: 118

revolution wrote:
kerr: fasm doesn't move the segment address to DS because there are no segment address registers in 32-bit protected mode. DS is a selector and it does not correspond to any address directly. The OS assigns the values for the selectors and user code can't control that. You simply do not need to change the value of any of the CS, DS, ..., SS registers.



oh, you speak i don't know.
so what do you move program header address to DS register?

_________________
I hope we will be good friends.
Post 10 Apr 2016, 09:49
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14795
Location: Lost in translation
kerr: For 32-bit protected mode (this is what Linux runs in) you do not need to touch DS for anything. If you do try to change DS then bad things will happen.

If you want to access any address in the program you should address it directly:

Code:
format elf ...
;...
label1:
;...
mov eax,label1
mov eax,[label1]
lea eax,[label1]
jmp label1
call label1
;...

Post 10 Apr 2016, 12:33
View user's profile Send private message Visit poster's website Reply with quote
kerr



Joined: 24 Feb 2016
Posts: 118

revolution wrote:
kerr: For 32-bit protected mode (this is what Linux runs in) you do not need to touch DS for anything. If you do try to change DS then bad things will happen.

If you want to access any address in the program you should address it directly:

Code:
format elf ...
;...
label1:
;...
mov eax,label1
mov eax,[label1]
lea eax,[label1]
jmp label1
call label1
;...




okey thank you good idea !
but my idea is move program header address to ds registar!

_________________
I hope we will be good friends.
Post 11 Apr 2016, 02:10
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14795
Location: Lost in translation
You can't. DS can't do that for you, it is not a segment register in PM32. You seem to have completely missed the point about DS being a selector.
Post 11 Apr 2016, 02:17
View user's profile Send private message Visit poster's website Reply with quote
kerr



Joined: 24 Feb 2016
Posts: 118

revolution wrote:
You can't. DS can't do that for you, it is not a segment register in PM32. You seem to have completely missed the point about DS being a selector.



oh !
that i don't know! You say what mean!

in memory isn't Physical address = Segment address +OFFSET address?

that how do you use segment +offset form physical address?
eg: [ds:esi]?
According to what you mean no segment, that DS segment cannot plus offset address...

_________________
I hope we will be good friends.
Post 11 Apr 2016, 05:36
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14795
Location: Lost in translation
For most PM OSes the DS, ES, CS and SS selectors are simply set so that the base address is 0x00000000. And you can't know the RAM physical address in most cases, you only know the logical address before paging is applied. So whether you use DS, or ES, or whatever, you always get the same address.

Note that, for example, the DS and CS registers will have different values but they will still point to the same memory address after translation through the selector tables.
Post 11 Apr 2016, 06:34
View user's profile Send private message Visit poster's website Reply with quote
kerr



Joined: 24 Feb 2016
Posts: 118

revolution wrote:
For most PM OSes the DS, ES, CS and SS selectors are simply set so that the base address is 0x00000000. And you can't know the RAM physical address in most cases, you only know the logical address before paging is applied. So whether you use DS, or ES, or whatever, you always get the same address.

Note that, for example, the DS and CS registers will have different values but they will still point to the same memory address after translation through the selector tables.




I'm confused.
can you tell me how to use ds segment +esi offset

_________________
I hope we will be good friends.
Post 11 Apr 2016, 08:43
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.