flat assembler
Message board for the users of flat assembler.

Index > Heap > Remarkable dates

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
hi
same had been asked at wasm.ru from my face
please make me a favour: compile pascal code below with a non Borland c/c++/etc and bring its assembly listing
yes you are right i'm an intolerant with my desires
also exploring hll shit level, shit level of myself
thanks
pascal code:
Code:
procedure TForm1.FormCreate(Sender: TObject);
const
  a:AnsiString = 't00x';
var
  i:dword;
begin
  asm
          hlt;
  end;
  i:=length(a);
  while (i>=0) and (a[i]=#0) do i:=i-1;
end;
    

use common string format if Ccc do not support indexed ones, i do not know Ccc
THANKS

for your information Delphi7 does it so:
Code:
CPU Disasm
Address    Hex dump            Command                                         Comments
0044D0F4    .  FFFFFFFF        dd      FFFFFFFF
0044D0F8    .  04000000        dd      00000004
0044D0FC    .  74 30 30 78     ascii   "t00x"
0044D100       00              db      00
0044D101       00              db      00
0044D102       00              db      00
0044D103       00              db      00
0044D104       F4              db      F4                                      ; char ''
0044D105   /.  A1 34ED4400     mov     eax,[dword ds:Project1.44ED34]          ; ASCII "t00x"
0044D10A   |.  E8 9173FBFF     call    Project1.004044A0                       ; strlen
0044D10F   |.  EB 01           jmp     short Project1.0044D112
0044D111   |>  48              /dec     eax
0044D112   |>  85C0            |test    eax,eax
0044D114   |.  72 0D           |jb      short Project1.0044D123                ; why to use CF?
0044D116   |.  8B15 34ED4400   |mov     edx,[dword ds:Project1.44ED34]         ; ASCII "t00x"
0044D11C   |.  807C02 FF 00    |cmp     [byte ds:eax+edx-1],0
0044D121   |.^ 74 EE           \je      short Project1.0044D111
0044D123   \>  C3              retn
    


for your information lazarus 0.9.28.2 does it so:
Code:
CPU Disasm
Address    Hex dump            Command                                         Comments
0041D3CD   /.  A1 30B45300     mov     eax,[dword ds:project1.53B430]          ; ASCII "t00x"
0041D3D2   |.  85C0            test    eax,eax
0041D3D4   |.  74 03           je      short project1.0041D3D9
0041D3D6   |.  8B40 FC         mov     eax,[dword ds:eax-4]
0041D3D9   |>  8945 F4         mov     [dword ss:ebp-0C],eax
0041D3DC   |.  EB 13           jmp     short project1.0041D3F1
0041D3DE   |   89F6            mov     esi,esi
0041D3E0   |>  8B45 F4         /mov     eax,[dword ss:ebp-0C]
0041D3E3   |.  BA 00000000     |mov     edx,0
0041D3E8   |.  83E8 01         |sub     eax,1
0041D3EB   |.  83DA 00         |sbb     edx,0
0041D3EE   |.  8945 F4         |mov     [dword ss:ebp-0C],eax
0041D3F1   |>  A1 30B45300     |mov     eax,[dword ds:project1.53B430]         ; ASCII "t00x"
0041D3F6   |.  8B55 F4         |mov     edx,[dword ss:ebp-0C]
0041D3F9   |.  8A4410 FF       |mov     al,[byte ds:edx+eax-1]
0041D3FD   |.  84C0            |test    al,al
0041D3FF   |.^ 74 DF           \je      short project1.0041D3E0
0041D401   |.  C9              leave
0041D402   \.  C3              retn
    


Last edited by edemko on 09 Jun 2010, 14:53; edited 1 time in total
Post 09 Jun 2010, 14:33
View user's profile Send private message Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
!possibly to Tomasz: as you can see the code is wrapped, could any fix that like in fasmw.exe?
Post 09 Jun 2010, 14:50
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
wouldn't it be better not to use calls to library, if compiler result is what interests you? This way I have to mess up the executable with library code.

Here's C source I used:
Code:
#include <string.h>
const char* a = "t00x";
int i;
int main() 
{
    i = strlen(a);
    while (i>=0 && a[i]=='\0') i--;
    return 0;
}
    


Here's result of Visual C v15.0 with /O2

Code:
; Listing generated by Microsoft (R) Optimizing Compiler Version 15.00.30729.01 

    TITLE   F:\_temp\edemko\prog.c
       .686P
       .XMM
        include listing.inc
 .model  flat

INCLUDELIB LIBCMT
INCLUDELIB OLDNAMES

PUBLIC      ??_C@_04GCJKACC@t00x?$AA@                       ; `string'
PUBLIC   _a
_DATA     SEGMENT
COMM _i:DWORD
_a      DD      FLAT:??_C@_04GCJKACC@t00x?$AA@
_DATA     ENDS
;       COMDAT ??_C@_04GCJKACC@t00x?$AA@
CONST       SEGMENT
??_C@_04GCJKACC@t00x?$AA@ DB 't00x', 00H           ; `string'
CONST    ENDS
PUBLIC  _main
; Function compile flags: /Ogtpy
;      COMDAT _main
_TEXT   SEGMENT
_main        PROC                                            ; COMDAT
; File f:\_temp\edemko\prog.c
; Line 5
        push    esi
; Line 6
     mov     esi, DWORD PTR _a
   mov     eax, esi
    lea     edx, DWORD PTR [eax+1]
      npad    4
$LL7@main:
 mov     cl, BYTE PTR [eax]
  inc     eax
 test    cl, cl
      jne     SHORT $LL7@main
     sub     eax, edx
    mov     DWORD PTR _i, eax
; Line 7
       js      SHORT $LN9@main
$LL2@main:
   cmp     BYTE PTR [esi+eax], 0
       jne     SHORT $LN9@main
     sub     eax, 1
      mov     DWORD PTR _i, eax
   jns     SHORT $LL2@main
$LN9@main:
; Line 8
       xor     eax, eax
    pop     esi
; Line 9
     ret     0
_main      ENDP
_TEXT   ENDS
END
    


Here's result of MinGW GCC v4.4.0 with -O2 (sorry for AT&T syntax)

Code:
       .file   "prog.c"
  .def    ___main;        .scl    2;      .type   32;     .endef
      .text
       .p2align 2,,3
.globl _main
       .def    _main;  .scl    2;      .type   32;     .endef
_main:
        pushl   %ebp
        movl    %esp, %ebp
  andl    $-16, %esp
  pushl   %edi
        subl    $12, %esp
   call    ___main
     movl    _a, %edx
    xorl    %eax, %eax
  movl    $-1, %ecx
   movl    %edx, %edi
  repne scasb
 notl    %ecx
        decl    %ecx
        movl    %ecx, _i
    testl   %ecx, %ecx
  js      L2
  addl    %ecx, %edx
  cmpb    $0, (%edx)
  je      L3
  jmp     L2
  .p2align 2,,3
L7:
    movb    -1(%edx), %al
       decl    %edx
        testb   %al, %al
    jne     L2
L3:
       decl    %ecx
        movl    %ecx, _i
    testl   %ecx, %ecx
  jns     L7
L2:
       xorl    %eax, %eax
  addl    $12, %esp
   popl    %edi
        leave
       ret
.globl _a
    .section .rdata,"dr"
LC0:
  .ascii "t00x\0"
  .data
       .align 4
_a:
 .long   LC0
 .comm   _i, 16   # 4 
    
Post 15 Jun 2010, 22:02
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
Using the GNU Compiler Collection if you are gcc interested.
Exempli gratia it says there are -O3 and some other optimizations available(enough dumps Smile.
Nice optimized dumps.
Eh, fasm is more rapid.
Happy, done, all is ok, one more institute exam left.
Thank you.
Embarassed
Post 16 Jun 2010, 07:22
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17344
Location: In your JS exploiting you and your system
revolution
vid wrote:
Here's result of MinGW GCC v4.4.0 with -O2 (sorry for AT&T syntax)
Code:
      .file   "prog.c"
  .def    ___main;        .scl    2;      .type   32;     .endef
      .text
       .p2align 2,,3
.globl _main
       .def    _main;  .scl    2;      .type   32;     .endef
_main:
        pushl   %ebp
        movl    %esp, %ebp
  andl    $-16, %esp
  pushl   %edi
        subl    $12, %esp
   call    ___main
     movl    _a, %edx
    xorl    %eax, %eax
  movl    $-1, %ecx
   movl    %edx, %edi
  repne scasb
 notl    %ecx
        decl    %ecx
        movl    %ecx, _i
    testl   %ecx, %ecx
  js      L2
  addl    %ecx, %edx
  cmpb    $0, (%edx)
  je      L3
  jmp     L2
  .p2align 2,,3
L7:
    movb    -1(%edx), %al
       decl    %edx
        testb   %al, %al
    jne     L2
L3:
       decl    %ecx
        movl    %ecx, _i
    testl   %ecx, %ecx
  jns     L7
L2:
       xorl    %eax, %eax
  addl    $12, %esp
   popl    %edi
        leave
       ret
.globl _a
    .section .rdata,"dr"
LC0:
  .ascii "t00x\0"
  .data
       .align 4
_a:
 .long   LC0
 .comm   _i, 16   # 4 
    
Very inefficient, it searches for zero twice. The first time it does it to determine the string length for the second time through.
vid wrote:
(sorry for AT&T syntax)
Image Bleeeaaargh <splat>. Oops, sorry for the messy vomit pile there, I'll clean it up right away.
Post 16 Jun 2010, 07:46
View user's profile Send private message Visit poster's website Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
I am grossed out by pretty much anything a HLL compiler generates.
But i am a firm believer that it has its place.
Mostly i use C to prototype code that would take forever in asm.
Then when it is C-fast/small i can think about asm instructions.

PS: Hope you get well soon revo!
Post 16 Jun 2010, 07:56
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:
Very inefficient, it searches for zero twice. The first time it does it to determine the string length for the second time through.
Well, that is an inefficiency carried from the HLL code itself (first the strlen() call, second the while loop). Note that the MSVC listing did this too, but not by using scasb.

Placing the "i" variable globally is not helping the optimization much.
Post 16 Jun 2010, 18:19
View user's profile Send private message Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
gcc avoided CLD, is it normal?
Olly's listing and the marks from us below i gonna show(link to this page) to the gcc team
Code:
CPU Disasm
Address  Hex dump          Command                                 Comments
00401318 /$  55            push    ebp                             ; enter 0,0
00401319 |.  89E5          mov     ebp,esp                         ; ...
0040131B |.  83E4 F0       and     esp,FFFFFFF0                    ; stack align 16
0040131E |.  57            push    edi                             ; did not explore
0040131F |.  83EC 0C       sub     esp,0C                          ; ...
00401322 |.  E8 39040000   call    operators.00401760              ; ...

00401327 |.  F4            hlt                                     ; hi Olly
00401328 |.  8B15 00204000 mov     edx,[dword ds:operators.402000] ; ASCII "Thank you!"
0040132E |.  31C0          xor     eax,eax                         ; why not to xor al,al
00401330 |.  B9 FFFFFFFF   mov     ecx,-1                          ; says optimized for speed
00401335 |.  89D7          mov     edi,edx
00401337 |.  F2:AE         repne scas [byte es:edi]                ; searching for the Arnold
00401339 |.  F7D1          not     ecx                             ; length trick
0040133B |.  49            dec     ecx                             ; ...
0040133C |.  890D 08404000 mov     [dword ds:operators.404008],ecx ; bad, store length
00401342 |.  85C9          test    ecx,ecx                         ; bad, loop entry condition wrong place
00401344 |.  78 1D         js      short operators.00401363        ; bad, so never jumps
00401346 |.  01CA          add     edx,ecx                         ; switch over string body at #0
00401348 |.  803A 00       cmp     [byte ds:edx],0                 ; bad, Arnold in AL, why not
0040134B |.  75 16         jne     short operators.00401363        ; bad, loop entry condition wrong place
0040134D |.  8D76 00       lea     esi,[esi]                       ; ???, interlals maybe
00401350 |>  49            /dec     ecx                            ; approach the end Smile
00401351 |.  890D 08404000 |mov     [dword ds:operators.404008],ecx; bad, why?
00401357 |.  85C9          |test    ecx,ecx                        ; i>=0?
00401359 |.  78 08         |js      short operators.00401363       ; -flags know
0040135B |.  8A42 FF       |mov     al,[byte ds:edx-1]
0040135E |.  4A            |dec     edx
0040135F |.  84C0          |test    al,al
00401361 |.^ 74 ED         \je      short operators.00401350

00401363 |>  31C0          xor     eax,eax
00401365 |.  83C4 0C       add     esp,0C
00401368 |.  5F            pop     edi
00401369 |.  C9            leave
0040136A \.  C3            retn
    

revolution, i've got some pills for you: revolution, revolution, revo-evolution, revo, fasm, fasm, board, arm, fasmarm, intel_syntax, ... Smile:

wow
мом
you corrected CODE section, thx
Post 16 Jun 2010, 18:36
View user's profile Send private message Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
LocoDelAssembly wrote:

Placing the "i" variable globally is not helping the optimization much.

gcc -O3(full optimize):
Code:
/*
int main()
{
  for(int i = 65535; i != 0; i--){
    asm(".intel_syntax; hlt; .att_syntax;");
  }
  return 0;
}
00401318 /$  55          push    ebp
00401319 |.  89E5        mov     ebp,esp
0040131B |.  83E4 F0     and     esp,FFFFFFF0
0040131E |.  E8 0D040000 call    operators.00401730

00401323 |.  31C0        xor     eax,eax
00401325 |.  8D76 00     lea     esi,[esi]
00401328 |>  F4          /hlt
00401329 |.  40          |inc     eax
0040132A |.  3D FFFF0000 |cmp     eax,0FFFF
0040132F |.^ 75 F7       \jne     short operators.00401328

00401331 |.  66:31C0     xor     ax,ax
00401334 |.  C9          leave
00401335 \.  C3          retn


int main()
{
  for(int i = 10; i != 0; i--){
    asm(".intel_syntax; hlt; .att_syntax;");
  }
  return 0;
}
00401318 /$  55         push    ebp
00401319 |.  89E5       mov     ebp,esp
0040131B |.  83E4 F0    and     esp,FFFFFFF0
0040131E |.  E8 0D040000call    operators.00401730
00401323 |.  F4         hlt
00401324 |.  F4         hlt
00401325 |.  F4         hlt
00401326 |.  F4         hlt
00401327 |.  F4         hlt
00401328 |.  F4         hlt
00401329 |.  F4         hlt
0040132A |.  F4         hlt
0040132B |.  F4         hlt
0040132C |.  F4         hlt
0040132D |.  31C0       xor     eax,eax
0040132F |.  C9         leave
00401330 \.  C3         retn
*/
    
Post 16 Jun 2010, 18:58
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
Amazing that -03 optimization retains ebp addressing...
Post 16 Jun 2010, 21:17
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
I think "-fomit-frame-pointer" will fix that, but I'm unsure of what you're talking about.
Post 16 Jun 2010, 21:45
View user's profile Send private message Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
i like this man


Description:
Filesize: 27.72 KB
Viewed: 6253 Time(s)

hard_coder.PNG


Post 24 Jun 2010, 03:05
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
haha, yeah. Feryno's code rules!

Ever tried "grep fuck" on his sources? Very Happy
Post 24 Jun 2010, 14:15
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
Image
Code:
fdbg.asm:
141:Rambo_WindowName_ClassName:
146:        call    rambo_generate_string 
4177: <- secret Rambo tricks
                                dq      CMD_RAMBO_IDPF
                                dq      CMD_RAMBO_FWW
                                dq      CMD_RAMBO_TFATT
                                dq      CMD_RAMBO_CCCD
                                dq      CMD_RAMBO_FB
                                dq      CMD_RAMBO_TLSC
                                dq      CMD_RAMBO_EHP
                                dq      CMD_RAMBO_IE

4684:        .Rambo                  db      0       ; fdbg anti-antidebugs' weapons, upto 8 weapons...
4985:Rambo_buf               rb      100h
    
Post 24 Jun 2010, 18:08
View user's profile Send private message Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
O. Henry - Biography & Works:
http://www.literaturecollection.com/a/o_henry/

I liked this story:
http://www.literaturecollection.com/a/o_henry/32/

All to be read once.
Have nice time guys.

edit:
free web downloader:
http://www.httrack.com

edit:
30 day trial down-loader, understands php-based pages
redit:
this one better http://www.tensons.com/
Post 09 Jul 2010, 20:56
View user's profile Send private message Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
wow
Image
Post 17 Jul 2010, 20:55
View user's profile Send private message Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
Image
Post 18 Jul 2010, 15:30
View user's profile Send private message Reply with quote
idle



Joined: 06 Jan 2011
Posts: 359
Location: Ukraine
idle
want same
Image
Post 13 Jun 2012, 08:01
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji
sorry edemko, Wink is dead.

very few comments and very few feedbacks,
Wink has never interested many people!

for now, i'm learning LabVIEW
Razz

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 14 Jun 2012, 07:58
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.