Recent Posts

Pages: [1] 2 3 ... 10
1
Irvine Book Questions. / Re: Turning a low case sentence to Title Case
« Last post by historyb on Today at 06:51:24 AM »
Thank you all!
2
it would be nice to have an explanation of what happens to variables put before main under the hood and is it really necessary to create a buffer and align pointer/eax to be able to inline asm movaps xmm0,var1234,mulps xmm0,var5678,movaps var1234,xmm0?in C++

3
You can do all this online.

The code produced by ml for this proc:
Code: [Select]
_mul77@4 PROC NEAR
        push    ebp                                     ; 0000 _ 55
        mov     ebp, esp                                ; 0001 _ 8B. EC
        add     esp, -4                                 ; 0003 _ 83. C4, FC
        mov     dword ptr [ebp-4H], 2004318071          ; 0006 _ C7. 45, FC, 77777777
        mov     eax, dword ptr [ebp-4H]                 ; 000D _ 8B. 45, FC
        mul     dword ptr [ebp+8H]                      ; 0010 _ F7. 65, 08
        leave                                           ; 0013 _ C9
        ret     4                                       ; 0014 _ C2, 0004
_mul77@4 ENDP

ml64:
Code: [Select]
mul77   PROC
        push    rbp                                     ; 0000 _ 55
        mov     rbp, rsp                                ; 0001 _ 48: 8B. EC
        add     rsp, -8                                 ; 0004 _ 48: 83. C4, F8
        mov     dword ptr [rbp-4H], 2004318071          ; 0008 _ C7. 45, FC, 77777777
        mov     eax, dword ptr [rbp-4H]                 ; 000F _ 8B. 45, FC
        mul     dword ptr [rbp+10H]                     ; 0012 _ F7. 65, 10
        leave                                           ; 0015 _ C9
        ret                                             ; 0016 _ C3
mul77   ENDP

The 64-bit version of gcc:
Code: [Select]
        push    rbp                                     ; 0000 _ 55
        mov     rbp, rsp                                ; 0001 _ 48: 89. E5
        sub     rsp, 16                                 ; 0004 _ 48: 83. EC, 10
        mov     dword ptr [rbp+10H], ecx                ; 0008 _ 89. 4D, 10
        mov     dword ptr [rbp-4H], 2004318071          ; 000B _ C7. 45, FC, 77777777
        mov     eax, dword ptr [rbp-4H]                 ; 0012 _ 8B. 45, FC
        movsxd  rdx, eax                                ; 0015 _ 48: 63. D0
        mov     eax, dword ptr [rbp+10H]                ; 0018 _ 8B. 45, 10
        cdqe                                            ; 001B _ 48: 98
        imul    rax, rdx                                ; 001D _ 48: 0F AF. C2
        add     rsp, 16                                 ; 0021 _ 48: 83. C4, 10
        pop     rbp                                     ; 0025 _ 5D
        ret                                             ; 0026 _ C3

-O2
Code: [Select]
foo     LABEL NEAR
        movsxd  rax, ecx                                ; 0000 _ 48: 63. C1
        imul    rax, rax, 2004318071                    ; 0003 _ 48: 69. C0, 77777777
        ret                                             ; 000A _ C3
4
All right, if you have no time, let's leave that for now.  :biggrin:

I know that GCC has not release but I don't use it in Windows, although I have cygwin and eclipse installed.
Well, actually I use it when I do avr or arm but I barely notice.
5
Even in release mode there are various possibilities to make it call the useless function, you will find them if you want.

Note that gcc doesn't have a "release mode" and a "debug mode"

Yeah, these modern compilers are incredibly clever, right? Even with -O1 it plays already foul. One would have to set up a testbed summing up foo(randomvalue) to force the compiler to do a proper job. No time for that today, though...
6
If you got problems use debug mode.
Even in release mode there are various possibilities to make it call the useless function, you will find them if you  want.
7
If you compile in release mode, VS will not even make the multiplication, it will infer immediately the result.

Right, and that is of course very helpful when analysing this problem ;)
8
Code: [Select]
unsigned long long foo(int factor)
{
return (unsigned long long)0x77777777*factor;
}

int main()
{
unsigned long long value=foo(0x12345678);
printf("Result:   %llu\nexpected: 612158616795740616", value);
getchar();
    return 0;
}

_main   PROC                  ; COMDAT
; Line 12
   push   ebp
   mov   ebp, esp
   and   esp, -8               ; fffffff8H
; Line 14
   push   142529284            ; 087ed304H
   push   -1001522744            ; c44df9c8H
   push   OFFSET ??_C@_0CM@MAJDCJPD@Result?3?5?5?5?$CFllu?6expected?3?56121586@
   call   _printf
   add   esp, 12               ; 0000000cH
; Line 15
   call   DWORD PTR __imp__getchar
; Line 16
   xor   eax, eax
; Line 17
   mov   esp, ebp
   pop   ebp
   ret   0
_main   ENDP

9
 :biggrin:

Like what? Pimping paint?  :lol:

https://gcc.godbolt.org/
10
JJ,

Are you compiling in release mode? of course not.
If you compile in release mode, VS will not even make the multiplication, it will infer immediately the result.
Pages: [1] 2 3 ... 10