0

I've been using Ubuntu up until a few weeks ago and now I'm back on Windows. I have a test coming up in basic assembly programming. I remember that while I was on Linux I could compile .s assembly files through terminal using gcc file.s, and it all worked fine.

But now that I'm on Windows, it doesn't work so great. Here's the code that I copied from my faculty's website (I didn't write it):

.intel_syntax noprefix

.data
    fmt_string: .asciz "Hello, world!\n"

.text
.global main

main:
    enter 0,0
    mov rax, 0
    lea rdi, fmt_string
    call printf
    mov rax, 0
    leave
    ret

I'm using MinGW in ordere to compile .c and .s files, and here's what I get after tried to compile this code:

enter image description here

Now, keep in mind that I'm only starting (trying to start) learning assembly so if you go all theoretical on me I'll probably have no idea what you're talking about.

All I want to know is whether I can compile this assembly code on Windows or if I should think about just going back to Linux.

phuclv
  • 37,963
  • 15
  • 156
  • 475
Koy
  • 486
  • 5
  • 16
  • 1
    [use `xor eax, eax` instead of `mov rax, 0`](https://stackoverflow.com/q/33666617/995714), it's 5/8 bytes shorter and has more advantages. And you don't need to use `lea` to load a constant to a register. Use mov instead – phuclv Sep 01 '18 at 08:32
  • Short: You cannot. You tried to compile a 64-bit source using Linux calling convention with a 32-bit compiler using Windows calling convention. – rkhb Sep 01 '18 at 08:36
  • 1
    Of course it is possible to use the 64-bit MingW variant to compile 64-bit code... However compiling 64-bit code using the 32-bit variant will get you nowhere. – Martin Rosenau Sep 01 '18 at 08:39
  • The Windows x64 calling convention is different from Linux's x86-64 System V calling convention. I think x86-64 MinGW would use the Windows calling convention, so you'd need to pass the first arg to printf in RCX, and reserve 32 bytes of shadow space before the `call`. If you don't want to port code to a different calling convention, you should stick with Linux (or the Linux subsystem for Windows). – Peter Cordes Sep 02 '18 at 15:32

0 Answers0