Author Topic: 64-bit Experiments  (Read 5790 times)


  • Guest
64-bit Experiments
« on: December 17, 2008, 04:40:17 AM »
Code: [Select]
;  nasm -f elf64 -o nilch.o nilch.asm

;  gcc -o donilch donilch.c nilch.o

global nostart

section .text


mov rcx, $0FFFF

dec rcx

jnz .again


Code: [Select]

int main(int argc, char *argv[])


printf( "done.\n" );
return 0;




  • Guest
Re: 64-bit Experiments
« Reply #1 on: December 17, 2008, 04:41:54 AM »
Code: [Select]
; nasm -f elf64 -o int.o int.asm
; ld -o int int.o

global _start
section .text
mov rax,1
mov rbx,0
int $80


Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2437
  • Country: us
Re: 64-bit Experiments
« Reply #2 on: December 18, 2008, 12:14:25 AM »
Hi Nathan,

Does this work? I was given to understand that the sys_call numbers have changed in 64-bit-land. I have this example - not tested by me. I don't recall where I got it - something posted by Chuck, I think(?).

Code: [Select]
section .data
    string1 db  "Hello World!",10,0

section .text
    global _start

        ; calculate the length of string
        mov     rdi, string1
        mov     rcx, -1
        xor     al,al
        repnz scasb

; place the length of the string in RDX
        mov     rdx, -2
        sub     rdx, rcx

; print the string using write() system call
        mov     rsi, string1
        push    0x1
        pop     rax
        mov     rdi,rax

; exit from the application here
        xor     rdi,rdi
        push    0x3c
        pop     rax

I've seen code in which "syscall" was a macro for "int 80h". I *think* this is the real syscall(?). I *think* int 80h would work, too(?). Dunno.

For the MicroSerfs, if any left, James Van Buskirk posted this one to a.l.a.:

Code: [Select]
extern   GetStdHandle
extern   WriteConsoleA
extern   ExitProcess

[SECTION .data]
   align 32
   dd   0
   db 'Hello, world!', 0dh, 0ah

[SECTION .text]
   global _MAIN__
   sub    rsp, 40
   mov    ecx, -11
   call   GetStdHandle
   mov    rcx, rax
   mov    rdx, _message
   mov    r8d, 15
   mov    r9, _dummy
   xor    eax, eax
   mov    [rsp-32], rax
   call   WriteConsoleA
   xor    ecx, ecx
   call   ExitProcess

; nasm -f win64 hello.asm

; link /subsystem:console hello.obj /defaultlib:Kernel32.lib /entry:_MAIN__

Again, not tested by me... Notice that both of these are *quite* different from the 32-bit version! One of these days I've gotta get me one of those new-fangled 64-bit thingummies... before they go all 128-bit on me...

Couple links...



  • Guest
Re: 64-bit Experiments
« Reply #3 on: December 18, 2008, 05:00:40 AM »
Hi Frank,

Yes, the 'int $80' works... er, rather it *seems* to.  I didn't bother to check for an exit code or trace it with a debugger.  I just know that I didn't get a segfault.

Thanks for the examples and links.  I will try those next.  This is definitely an area where the jungle needs pushed-back some and the trail widened.

As for the "new-fangled" thingy, I'm really not that impressed.  The really impressive jumps were back in the days when we went from like 25/33MHz CPUs up to 100/500MHz -- that was when you could really notice the difference!   Also, these large LCD monitors appear to be designed for an insanely high resolutions -- at "readable" resolutions the text looks blurry.  But the 64-bit... yes, that, I hope, will be the fun part.