Author Topic: compile a program  (Read 14356 times)

Offline Balsiger

  • Jr. Member
  • *
  • Posts: 2
compile a program
« on: May 19, 2014, 03:35:03 PM »
Hello,
my english is maybe not very good. So please forgive me.
When I compile a program comes the message, that it is not compatible with 64 bit.
Please tell me, how must I compile a program that it runs on windows 64 bit?
For example a simple program that writes hello world to the console.
Please tell me all I need to know that the program writes hello world.

segment code
 
start:
mov ax, data
mov ds, ax
 
mov dx, hello
mov ah, 09h
int 21h
 
mov al, 0
mov ah, 4Ch
int 21h
 
segment data
hello: db 'Hello World!', 13, 10, '$'

Offline encryptor256

  • Full Member
  • **
  • Posts: 250
  • Country: lv
  • Win64 .
    • On Youtube: encryptor256
Re: compile a program
« Reply #1 on: May 19, 2014, 03:49:54 PM »
Hello,
my english is maybe not very good. So please forgive me.

I forgive you!  ;D


Hi! That code will not work, it looks like it's for x16.

Win64 Hello world using GCC:

1. Install development environment: MinGW-w64: GCC for both x64 & x86 Windows!

2. Helloworld.asm:
Code: [Select]
bits 64

section .data

message: db "Hello World!!!",0


section .text

global main
extern printf

main:
sub rsp,0x28


mov rcx,message
call printf

add rsp,0x28
ret

3. Compile: "nasm.exe -f win64 helloworld.asm -o helloworld.obj".

4. Build: "gcc helloworld.obj -o helloworld.exe".

And that's it!
Encryptor256's Investigation \ Research Department.

Offline Balsiger

  • Jr. Member
  • *
  • Posts: 2
Re: compile a program
« Reply #2 on: May 19, 2014, 03:53:26 PM »
Thank  you for your very fast answer.
I will try what you told.
And tell you if it worked.

Offline encryptor256

  • Full Member
  • **
  • Posts: 250
  • Country: lv
  • Win64 .
    • On Youtube: encryptor256
Re: compile a program
« Reply #3 on: May 19, 2014, 04:18:51 PM »
Thank  you for your very fast answer.
I will try what you told.
And tell you if it worked.

Line[0]: Okey, Cool! I'm waiting... Don't forget to report about how it worked.
Line[1]: Maybe you will need to add gcc and nasm to environment variables, so it can be accessed trough console - cmd. (Well, at least it's more comfortable if they are added to environment variables).
Encryptor256's Investigation \ Research Department.

Offline z80a

  • Jr. Member
  • *
  • Posts: 20
Re: compile a program
« Reply #4 on: May 21, 2014, 01:56:44 AM »
That program is written for MS-DOS. You could run it in "dosbox" in Linux. This is the program
in ".COM" format. DOS used "INT 21h", whereas 32 bit Linux uses "INT 80h" and 64 bit uses SYSCALL.
Here's an example of your code that runs under "DOSBOX" within Linux. Haven't tried under Windows.

Code: [Select]
; Compiled with NASM, trace through with either GRDB.EXE or DEBUG.EXE
; COMPILE CMD:  C:\>nasm hello.asm -o hello.com
;============================================================================
;
        bits    16          ;16 bit program (DOS)
        org     100h        ;All .COM files origin
        jmp     _start      ;We jump over data
;
; Data section.
;
msg     db      'Hello World!!!',0Ah,0Dh,'$'
;
; Code start.
;
_start:
;
        mov     ah,09h      ;DOS print string call
        mov     dx,msg      ;Point to message
        int     21h         ;* DOS call
;
;Exit program.
;
        mov     ah,4ch      ;Exit with errorlevel
        mov     al,00h      ; errorlevel=0
        int     21h         ;* DOS call