Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Moving from 16 bit x86 to x86-64 assembly language.

assembly

  • Please log in to reply
11 replies to this topic

#1 charles-eng

charles-eng

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 103 posts
  • Programming Language:C, Java, Assembly
  • Learning:C++, C#, Python, Transact-SQL

Posted 14 March 2012 - 09:51 PM

Hi, I have experience using 16 bit real mode assembler (I was taught that at school) and now I want to jump in the 64 bit wagon. I used to use interrupts for managing i/o but I know they are gone in 64 bit stuff so how can I print my output? . I've been thinking to use C's printf but I really don't know how to call it (maybe call _printf) and link it using NASM.

Thanks in advance and any piece of advice regarding 64 bit assembly will be apreciated.
  • 0

#2 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 15 March 2012 - 11:49 AM

What operating system and compiler are you using? I'm going to guess GCC on Linux. In 16- and 32-bit programs GCC passed arguments on the stack (with few exceptions). In 64-bit, most arguments are passed in registers, with the stack only holding extra arguments if there are more arguments than registers. The order of the registers is RDI, RSI, RDX, RCX, R8, and R9.

EDIT: Ignore my statement about it not working for the C library. I was messing up the linking.

Edited by dargueta, 15 March 2012 - 11:47 PM.

  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#3 untitled_1

untitled_1

    CC Addict

  • Validating
  • PipPipPipPipPip
  • 129 posts
  • Location:3rd rock from the sun
  • Programming Language:C, C++, Delphi/Object Pascal, Assembly
  • Learning:Python, Perl, Ada, Fortran, Bash

Posted 17 March 2012 - 12:15 AM

There are still interrupts with 64 bit mode, they work in more or less the same way as always but if you are trying to access interrupts on Vista or win7 as far as I know you cant make calls to any INT function
  • 0

#4 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 17 March 2012 - 09:10 AM

You can do them in XP as well as long as it's in a COM program, in which case you're limited to 64K for code, stack, and data. Raw binary, basically. No symbol information, no sections, nothing.
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#5 charles-eng

charles-eng

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 103 posts
  • Programming Language:C, Java, Assembly
  • Learning:C++, C#, Python, Transact-SQL

Posted 18 March 2012 - 10:24 PM

You can do them in XP as well as long as it's in a COM program, in which case you're limited to 64K for code, stack, and data. Raw binary, basically. No symbol information, no sections, nothing.


I don't know why, but that sounds like fun. I intend to write programs for LINUX and win7 so i guess i'll have to learn win64 and the different options of int 80h right?
  • 0

#6 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 19 March 2012 - 04:53 PM

int 0x80 stuff works for Linux only. You can also use the sysenter and sysexit instructions which is a more modern form of doing the same thing, as interrupts have a comparatively large overhead. Windows requires calls to the WinAPI functions.

EDIT: To avoid confusing readers I've edited this post to remove incorrect information that was in it before. The stuff above is correct.

Edited by dargueta, 19 March 2012 - 06:10 PM.

  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#7 RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1310 posts
  • Location:C:\Countries\US
  • Programming Language:C, Java, C++, PHP, Python, JavaScript

Posted 19 March 2012 - 05:54 PM

Don't you need to use import functions from the system DLLs? Or is Win64 different from Win32?
  • 0
Regards,
RR

#8 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 19 March 2012 - 06:06 PM

Right. I was under the impression that you could make direct system calls but after checking I realized I was wrong. My bad. :D
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#9 charles-eng

charles-eng

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 103 posts
  • Programming Language:C, Java, Assembly
  • Learning:C++, C#, Python, Transact-SQL

Posted 20 March 2012 - 04:23 PM

Right. I was under the impression that you could make direct system calls but after checking I realized I was wrong. My bad. :D

Ok. I've cheched the tutorials regarding win32 (i suposse win64 is not that different). Regarding Linux, can you reccommend any good tutorials about sysenter and sysexit?
  • 0

#10 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 21 March 2012 - 11:23 AM

Sysenter Based System Call Mechanism in Linux 2.6
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#11 charles-eng

charles-eng

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 103 posts
  • Programming Language:C, Java, Assembly
  • Learning:C++, C#, Python, Transact-SQL

Posted 23 March 2012 - 09:36 AM

Sysenter Based System Call Mechanism in Linux 2.6

Thanks a lot man, I'm begining to see why linux is so loved among programmers.
  • 0

#12 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 23 March 2012 - 09:36 AM

Simple yet powerful. Yep.
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'






Also tagged with one or more of these keywords: assembly

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download