Jump to content

Should I use x64 Assembly?

- - - - -

  • Please log in to reply
12 replies to this topic

#1
DarkLordoftheMonkeys

DarkLordoftheMonkeys

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 255 posts
I have a MacBook that I got new in 2008 with Mac OS X Leopard and an Intel dual core processor, and I'm pretty sure it's 64 bit. I tried copying a "Hello world" program in x86 from the Wikipedia article, and it didn't compile, so x64 is pretty much my last hope to figure out what kind of assembler my computer uses. Also, I just saw this XKCD strip:

xkcd - A webcomic of romance, sarcasm, math, and language - By Randall Munroe

Do you I could program my computer with x64 Assembly?

EDIT: For further clarification, I'm using GCC to compile my Assembly code. I tried it on a .s file that GCC created from a C source code file, and it compiled fine, so I know GCC can be used as an assembler. I just don't know what kind of assembly it is.
Life's too short to be cool. Be a nerd.

#2
JewFro297

JewFro297

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 224 posts
if it's an intel dual core from 2008 it's x64. x86 32 bit should run on your computer though. x86 might be referring to 16 bit in the wiki article. so try and find an x86-32 or x86_64 asm file. And make sure it doesn't rely on interrupts from the operating system.
Yea Dat's right.
Apple sucks :thumbup:
[SIGPIC][/SIGPIC]

#3
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
My guess is its NASM, but post the .s file so I can double-check. JewFro is almost right about x86 running on 64-bit processors. To implement support for the extra registers added to the Intel64 and IA-64 architectures, Intel was forced to blow away certain encodings of the INC/DEC instructions to use as extension prefixes. On x86 an INC or DEC instruction will work fine. Intel64 or IA-64 will choke on the one-byte shorthand encodings (0x40-0x47) for 16- and 32-bit increments.

There are a few things wrong with expecting the Wikipedia example to work:
1) It uses DOS interrupts. This will work only on Windows (or DosEMU on *nix systems) if you compile to a COM program (i.e. raw binary with no headers.) Compiling to an EXE will cause it to explode, as the DOS interrupts are unavailable to EXE programs. *nix systems will not allow you to execute a pure binary without headers, so COM won't work on them.
2) It's written in MASM. GCC will gag on MASM. Use NASM.
sudo rm -rf /

#4
JewFro297

JewFro297

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 224 posts
oh also I didn't notice you were using GCC. GCC uses AT&T syntax which is opposite of intel syntax. NASM MASM and TASM are some good intel syntax based compilers. I prefer NASM because it gives you absolute control.
Yea Dat's right.
Apple sucks :thumbup:
[SIGPIC][/SIGPIC]

#5
DarkLordoftheMonkeys

DarkLordoftheMonkeys

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 255 posts

JewFro297 said:

oh also I didn't notice you were using GCC. GCC uses AT&T syntax which is opposite of intel syntax. NASM MASM and TASM are some good intel syntax based compilers. I prefer NASM because it gives you absolute control.

How could GCC compile a dialect of Assembly that is incompatible with the hardware?
Life's too short to be cool. Be a nerd.

#6
JewFro297

JewFro297

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 224 posts
AT&T syntax is only a compiler syntax, in the end all assembly compilers generate the same type of machine code no mater what the dialect. Sort of like how C++ and BASIC both create programs for the x86 platform but look nothing alike.
Yea Dat's right.
Apple sucks :thumbup:
[SIGPIC][/SIGPIC]

#7
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
I definitely agree with JewFro as far as NASM goes. You can download it here. The main site for NASM is here.

Just to give you an example of how powerful NASM is: I'm working on creating a library of macros (#defines except more powerful) that can make assembly language more high-level. So you can turn this:


_print_args:

    ;2 arguments, 4 locals

    beginfunc   8, 16

    ;save required registers

    trashes     ebx, esi, edi

    parameter   DWORD argc, DWORD argv

    

    mkstr   errnarg     "Wrong number of arguments."

    mkstr   donestr     "Done."

    

    if argc le 2

        printf  errnarg

        exit    -1

    else

        dec     argc

    endif

    

    mov     edx, argv

    add     edx, 4


    ;for(ecx = 0; ecx < argc; ecx += 1)

    for ecx, 1, b, argc, 1

        lea     eax, [edx + ecx*4]

        printf  eax

    endfor

    ;automatically clean up stack & restore trashed regs

    endfunc

The only thing that doesn't fully work right now is parameter, but I'm getting there.
sudo rm -rf /

#8
JewFro297

JewFro297

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 224 posts
nice, you should make a new language using it then create a compiler that makes it look like it's not even assembly then see who notices it's really just assembly in disguise with high level ness
Yea Dat's right.
Apple sucks :thumbup:
[SIGPIC][/SIGPIC]

#9
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
It makes it really easy to code, but sometimes the code isn't optimized too well because it has to work for everything. But yeah, I guess I could do that. Tweak it a bit.
sudo rm -rf /

#10
JewFro297

JewFro297

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 224 posts
dat would be a pretty cool prank, kinda like the kde 4 as vista on youtube
Yea Dat's right.
Apple sucks :thumbup:
[SIGPIC][/SIGPIC]

#11
DarkLordoftheMonkeys

DarkLordoftheMonkeys

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 255 posts

JewFro297 said:

nice, you should make a new language using it then create a compiler that makes it look like it's not even assembly then see who notices it's really just assembly in disguise with high level ness

I think that's how most compilers work, although there is the added task of parsing and lexical analysis. But still, it all boils down to translating more abstract, high level instructions into their low level equivalents.
Life's too short to be cool. Be a nerd.

#12
JewFro297

JewFro297

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 224 posts
lol kinda, but like C++ compiles into assembly then machine code (or straight to machine code) but if you just create a bunch of libraries for NASM then it would be a little different
Yea Dat's right.
Apple sucks :thumbup:
[SIGPIC][/SIGPIC]




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users