public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Jesse Thompson <jesset@gmail.com>
To: cygwin@cygwin.com
Subject: Request for an example x68 assembler portable Hello World script
Date: Fri, 26 Apr 2019 07:25:00 -0000	[thread overview]
Message-ID: <CA+wh7Kg4UAO+_ZBONXbJ=3Hf9Tz6LSX2DX+LQNPLYqty4wkTag@mail.gmail.com> (raw)

I would like to learn how to write assembly programs for the command line
that with as little alteration as is feasable will compile both in Cygwin
and in other flavors of Unix like Linux and/or FreeBSD.

I am targeting only x64 CPUs and I'm perfectly happy to use libc calls
instead of direct syscalls or interrupts. I'm hoping to use nasm+gcc, or
perhaps fasm to do the deed. Crosspiling is not a concern, I'll build
cygwin binaries in cygwin and unix binaries in unix.

But I'm confused by the differences in calling convention/ABI between
Windows and/or Cygwin and Linux?

For example, I can get this to compile and run in Cygwin:

```
        global  main
        extern  puts
        section .text
main:
        sub     rsp, 20h                        ; Reserve the shadow space
        mov     rcx, message                    ; First argument is address
of message
        call    puts                            ; puts(message)
        add     rsp, 20h                        ; Remove shadow space
        ret
message:
        db      'Hello', 0                      ; C strings need a zero
byte at the end
```


but it segfaults in Linux (and complains about "Symbol `puts' causes
overflow in R_X86_64_PC32 relocation")

and I can get the following to compile and run in Linux:
```
    extern puts
    global main

section .text
main:
    mov rdi,message
    call puts
    ret

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

but *that* segfaults in cygwin.

TL;DR: I think I could get a lot more done if I could start from a single
Hello World asm file that can compile and run in both places, calling out
to puts or something simple like that.

Any help would be appreciated, I hope everything about my question makes
sense. :)

- - Jesse

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

             reply	other threads:[~2019-04-26  7:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-26  7:25 Jesse Thompson [this message]
2019-04-26 11:16 ` Eliot Moss
2019-04-26 21:04 ` Jesse Thompson
2019-04-27  1:56   ` Doug Henderson
2019-04-27 18:35   ` bzs
2019-04-28 20:00   ` Eliot Moss
2019-04-29 14:29     ` Sam Habiel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+wh7Kg4UAO+_ZBONXbJ=3Hf9Tz6LSX2DX+LQNPLYqty4wkTag@mail.gmail.com' \
    --to=jesset@gmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).