Re: about execute assembly exapmles under freebsd

From: Ryan Sommers (ryans_at_gamersimpact.com)
Date: 04/24/05

  • Next message: Daniel O'Connor: "Re: region code in cdrecord"
    Date: Sun, 24 Apr 2005 06:06:22 -0500
    To: "Tetsuji \"Maverick\" Rai" <maverick31337@vfemail.net>
    
    

    Something else than can be useful is to use inline assembly and the -S
    switch for GCC (gcc -S sourcefile, produces sourcesfile.s which is the
    assembly that would have been sent to gas if you had specified -o).

    Inline assembly example:

    (ryans@blue)~:cat test.c
    int
    main()
    {
    int input=0;
    void *edx, *ebx, *ecx, *eax;
    asm("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (input));
    printf("CPUid returned: EAX=%0.8x EBX=%0.8x ECX=%0.8x EDX=%0.8x\n", eax,
    ebx, ecx, edx);
    return 1;
    }
    (ryans@blue)~:./test
    CPUid returned: EAX=0001 EBX=68747541 ECX=444d4163 EDX=69746e65
    (ryans@blue)~:perl -e 'print
    "\x41\x75\x74\x68\x65\x6e\x74\x69\x63\x41\x4d\x44\n";'
    AuthenticAMD
    (ryans@blue)~:

    NOTE: If the order in the Perl command confused you, remember,
    byte-ordering. :) Little-endian you have to reverse the bytes.

    -- 
    Ryan Sommers
    ryans@gamersimpact.com
    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
    

  • Next message: Daniel O'Connor: "Re: region code in cdrecord"

    Relevant Pages

    • Re: data types
      ... Usually short is smaller than an int. ... Your compiler is either *really* old or broken or both. ... recommend either a version of gcc,, or Visual Studio ... Microsoft's Visual Studio Express has an onerous EULA). ...
      (comp.lang.c)
    • Re: gcc bug? Openoffice port impossibel to compile on 4.8
      ... remove this silly "bitten by the Linux bug" and the red-herring of gcc ... struct bar {int a; int b;} dapper; ... The *warning* emitted by gcc when enough analysis is done (e.g. ...
      (freebsd-hackers)
    • Re: Amusing C, amusing compiler
      ... int foo ... FWIW, gcc 3.3.3, when fed ... int qux(struct foo *f) { ... lda $30,-32 ...
      (comp.lang.c)
    • Re: gcc prototype oddity
      ... [correctly produces an error on gcc, but said error has weird contents] ... > 'int promotion' assumption will no longer be ... specifier shall be given in the declaration specifiers in each ... > implementation of the C99 spec in the error handling ...
      (comp.lang.c)
    • Re: help with type-punned warning please
      ... >using gcc). ... signal processing CPUs -- and objects with types like "int" and ... If some pointer might ... provided the compiler is sufficiently stupid (and/or run with "do ...
      (comp.lang.c)