flat assembler
Message board for the users of flat assembler.

Index > Heap > will compiler output 64bit instructions on 64bit system?

Author
Thread Post new topic Reply to topic
m



Joined: 28 Dec 2006
Posts: 304
Location: in
m
i created a test file in .c and compiled with gcc (on ubuntu, 64bit intel) but it is outputting all 32bit instructions.. ? Shocked

as an aside, is it perfectly ok to write/execute 32 bit code under 64 bit processor?

_________________
Attitude!
Post 30 May 2009, 10:55
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
GCC should be able to output either 32-bit or 64-bit given the correct command line options (isn't it --arch, or something like that?). All x86-64 processors I know of allow 32-bit code to run in compatitblity mode.
Post 30 May 2009, 15:00
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
If we are talking about x86_64 (aka AMD64) then it is OK to execute 32 bits code. Also, if your distro is for 32 bits then you have no other choice than 32-bit code.

To compile for different "bitness" you can do this: "gcc -m32 ..." for 32-bits and "gcc -m64 ..." for 64 bit. But again note that you need to have the AMD64 version of Ubuntu to execute programs generated with the latter command and you may need to download the libc-dev packages for the target architecture (via Synaptic for example).
Post 30 May 2009, 17:06
View user's profile Send private message Reply with quote
manfred



Joined: 28 Feb 2009
Posts: 43
Location: Racibórz, Poland
manfred
LocoDelAssembly wrote:
But again note that you need to have the AMD64 version of Ubuntu to execute programs generated with the latter command
Have you heard about cross compilers? I can e.g. create an application for ARM on x86.

_________________
Sorry for my English...
Post 30 May 2009, 17:16
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
execute =/= compile Wink

_________________
Previously known as The_Grey_Beast
Post 30 May 2009, 17:48
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:

Have you heard about cross compilers? I can e.g. create an application for ARM on x86.

Yep, I've even used revolution's fasm port to generate an executable for a smart phone (ARM architecture), on my Windows with an Athlon (K7, i.e., x86 architecture).

However what I've said remains true, I can't execute that ARM executable on my Athlon no matter if I remove Windows and install Linux. (The smart phone was running Linux)

PS: Yes, I could use an emulator, obviously I'm talking about executing executable images natively.
Post 30 May 2009, 19:55
View user's profile Send private message Reply with quote
m



Joined: 28 Dec 2006
Posts: 304
Location: in
m
thanks all,
can i get a really good link for "programming in 64 on linux and/or windows" ?
using fasm ? Smile

_________________
Attitude!
Post 02 Jun 2009, 06:34
View user's profile Send private message Reply with quote
mattst88



Joined: 12 May 2006
Posts: 260
Location: South Carolina
mattst88
Are you sure it's creating 32-bit executables? The file program will tell you.

Code:
$ file /bin/bzip2 
/bin/bzip2: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), stripped    
Post 03 Jun 2009, 04:18
View user's profile Send private message Visit poster's website Reply with quote
m



Joined: 28 Dec 2006
Posts: 304
Location: in
m
mattst88, the compiler is generating all 32bit registers/instructions only. executable file type is:

ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for GNU/Linux 2.6.8, dynamically linked (uses shared libs), not stripped

so that's fine.

actually...
i am struggling a lot in 64bit programming, i am comfortable with 32 bit, 16 bit was way before my time, and 64 bit PC is a recent thing for me (i got it 6months back)...

any help for 64bit programming in linux using fasm?

_________________
Attitude!
Post 04 Jun 2009, 07:17
View user's profile Send private message Reply with quote
mattst88



Joined: 12 May 2006
Posts: 260
Location: South Carolina
mattst88
m wrote:
mattst88, the compiler is generating all 32bit registers/instructions only.


What evidence of this do you have? Your 'file' output certainly does not corroborate this.

_________________
My x86 Instruction Reference -- includes SSE, SSE2, SSE3, SSSE3, SSE4 instructions.
Assembly Programmer's Journal
Post 12 Jun 2009, 15:43
View user's profile Send private message Visit poster's website Reply with quote
m



Joined: 28 Dec 2006
Posts: 304
Location: in
m
yes, i run gcc like this to produce the intermediate assembly:
gcc -S t.c
Code:
int main() {
    printf("%d\n", atoi("4garbage") + 1);

      return 0;
}
    

and i seen all 32bit instructions:
cat t.s
Code:
    .file   "t.c"
     .section        .rodata
.LC0:
        .string "4garbage"
.LC1:
   .string "%d\n"
   .text
.globl main
        .type   main, @function
main:
.LFB2:
  pushq   %rbp
.LCFI0:
 movq    %rsp, %rbp
.LCFI1:
   movl    $.LC0, %edi
 movl    $0, %eax
    call    atoi
        leal    1(%rax), %esi
       movl    $.LC1, %edi
 movl    $0, %eax
    call    printf
      movl    $0, %eax
    leave
       ret
.LFE2:
   .size   main, .-main
        .section        .eh_frame,"a",@progbits
.Lframe1:
  .long   .LECIE1-.LSCIE1
.LSCIE1:
     .long   0x0
 .byte   0x1
 .string "zR"
      .uleb128 0x1
        .sleb128 -8
 .byte   0x10
        .uleb128 0x1
        .byte   0x3
 .byte   0xc
 .uleb128 0x7
        .uleb128 0x8
        .byte   0x90
        .uleb128 0x1
        .align 8
.LECIE1:
.LSFDE1:
    .long   .LEFDE1-.LASFDE1
.LASFDE1:
   .long   .LASFDE1-.Lframe1
   .long   .LFB2
       .long   .LFE2-.LFB2
 .uleb128 0x0
        .byte   0x4
 .long   .LCFI0-.LFB2
        .byte   0xe
 .uleb128 0x10
       .byte   0x86
        .uleb128 0x2
        .byte   0x4
 .long   .LCFI1-.LCFI0
       .byte   0xd
 .uleb128 0x6
        .align 8
.LEFDE1:
    .ident  "GCC: (GNU) 4.2.3 (Ubuntu 4.2.3-2ubuntu7)"
    .section        .note.GNU-stack,"",@progbits
    



although i found some really nice examples on this board for 64bit on linux Smile

PS:
oops!
this time it did use some 64bit registers Very Happy
Post 16 Jun 2009, 09:15
View user's profile Send private message Reply with quote
mattst88



Joined: 12 May 2006
Posts: 260
Location: South Carolina
mattst88
No, it's 64-bit code, for instance:

Code:
leal    1(%rax), %esi     


Notice the usage of rax.
Post 16 Jun 2009, 17:11
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
m wrote:
i am comfortable with 32 bit
same, they should have just added extra 4GB segments, and old programs or programs needing less than 4GB would have used just the default 0x00000000 segment Sad
Everyone happier, compatibility simpler, 32-bit programs would NOT require a different API.

...except those wanting a flat addressing space with shit larger than 4GB... Rolling Eyes

_________________
Previously known as The_Grey_Beast
Post 16 Jun 2009, 17:14
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1160
Azu
bitRAKE wrote:
All x86-64 processors I know of allow 32-bit code to run in compatitblity mode.
Then why does windows need WoW64? Confused
Post 17 Jun 2009, 23:30
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
mattst88



Joined: 12 May 2006
Posts: 260
Location: South Carolina
mattst88
Azu wrote:
bitRAKE wrote:
All x86-64 processors I know of allow 32-bit code to run in compatitblity mode.
Then why does windows need WoW64? Confused


Because there's a software aspect needed as well.

_________________
My x86 Instruction Reference -- includes SSE, SSE2, SSE3, SSSE3, SSE4 instructions.
Assembly Programmer's Journal
Post 20 Jun 2009, 16:26
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
It's for the API.

again, none of this would be needed if they added smart "segments"
Post 21 Jun 2009, 00:28
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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 can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.