Cygwin: Developing assembly language?

First, I'm not sure if this should be part of thread I started yesterday on the build and stack , but I think the question I ask here is completely different.

I'm trying to understand that it was Cygwin , through Wikipedia and Google, that I was not very lucky. I just started assembly programming on Linux using gcc gas assembler. I use the car during lunch to have only Windows on it. I wanted to practice building language programming here, so I thought Cygwin would be able to help.

I hardly believed that the code that I wrote on Linux could simply be compiled and run on Windows using Cygwin. Cygwin allows me to compile code:

as someAssmProg.as -o someAssmProg.o
ld someAssmProg.o -o someAssmProg

But if I try to run the code under Cygwin,

./someAssmProg

I get an error unhandled win32 exception

Now I assume that this is because the code I'm writing is for Linux. I thought Sigwin would deal with this. Is Cygwin really designed to develop a Unix-style command-line Windows application?

Again I know that this is probably obvious to most people here, but I'm really confused!

PS I tried AndLinux before for Windows, but it's a rather complicated installation.

+5
source share
4 answers

Cygwin - , Unix/Linux Windows. , Windows, .. - Windows, Linux. , Windows, - , Linux ( DOS, ).

+6

Cygwin. , , theres , , Windows main. gcc , .

. hello.s:

.intel_syntax noprefix

.section .text

.globl _main
_main:
        enter 0, 0

        // welcome message
        push    OFFSET s_HelloWorld
        call    _printf
        pop     eax

        // add three numbers
        push    2
        push    4
        push    5
        call    _addThree
        add     esp, 3 * 4

        // print returned value
        push    eax
        push    OFFSET s_PercentD
        call    _printf
        add     esp, 2 * 4

        xor     eax, eax
        leave
        ret

// Add three numbers
_addThree:
       enter    0, 0
       mov      eax, DWORD PTR [ebp + 8]
       add      eax, DWORD PTR [ebp + 12]
       add      eax, DWORD PTR [ebp + 16]
       leave
       ret

.section .rdata

s_HelloWorld:
       .ascii  "Hello, world.\n\0"
s_PercentD:
       .asciz "%d\n"

$ gcc -mno-cygwin hello.s -o hello && ./hello
Hello, world.
11

AMD64 Architecture. C -; , , ?

, Cygwin 32- ; ( ) - 64 , 64- .

+2

- VM ( VirtualBox somesuch) Linux . , , , .

+1

, , -mconsole cygwin foo.c gdb. ,

$ cat foo.c
int main( void )
{
        __asm__ ( "mov $5, %rax" );
        return 0;
}
$ make
gcc -ggdb -Wall -mconsole -o foo.o -c foo.c
gcc -ggdb -o foo foo.o -lm
$ gdb ./foo.exe
GNU gdb (GDB) (Cygwin 7.10.1-1) 7.10.1
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-cygwin".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./foo.exe...done.
(gdb) l
1       int main( void )
2       {
3               __asm__ ( "mov $5, %rax" );
4               return 0;
5       }
(gdb) b 3
Breakpoint 1 at 0x1004010ed: file foo.c, line 3.
(gdb) r
Starting program: /cygdrive/c/C++/C/foo.exe
[New Thread 6724.0x13d0]
[New Thread 6724.0x1890]
[New Thread 6724.0x8e0]
[New Thread 6724.0xd84]

Breakpoint 1, main () at foo.c:3
3               __asm__ ( "mov $5, %rax" );
(gdb) info registers rax
rax            0x0      0
(gdb) s
4               return 0;
(gdb) info registers rax
rax            0x5      5
(gdb) c
Continuing.
[Thread 6724.0x1890 exited with code 0]
[Thread 6724.0x8e0 exited with code 0]
[Thread 6724.0xd84 exited with code 0]
[New Thread 6724.0x1368]
[Inferior 1 (process 6724) exited normally]
(gdb)
0
source

All Articles