flat assembler
Message board for the users of flat assembler.

Index > Main > 88 Byte's !!! Challenge 2013-Aug-10

Author
Thread Post new topic Reply to topic
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386 10 Aug 2013, 08:24
...

Code:
; FASM challenge (again Very Happy) ... What is this code supposed to do ???

; (CL) 2013-Aug-10

; 88 Byte's in use32 (if "in0" "in1" "out0" evaluate into [EBP+SINT8]
; and 3 PUSH'es and 3 POPE'es are commented out) , MD5 =
; 0E26'E101'D10A'87A5'C948'FCF8'20A3'9320 (if the EBP stuff kept as-is)

format binary as "BIN" ; LADEN
use32 ; abuse64
org $1234'FEDC ; YES we CAN (be PIC ...)

virtual at (ebp+4)
  in0:  dd ?
  in1:  dd ?
  out0: dd ?
end virtual

define pope pop

        ; push   ebx
        ; push   esi
        ; push   edi

        call   msdog
        db     129,10,133,10,7,26,132,2,26,4
 msdog: pope   edx

        mov    esi, [in0]
        mov    ecx, [in1]
        xor    edi, edi       ; MOVNTQ EDI, 0

 mscat: lodsb
        push   ecx
        push   edx

        mov    cl, 31
        mov    ah, 32
        cmp    al, ah
        jb     short lzhen
        cmp    al, 126
        ja     short lzhen
        mov    cl, 0
        jmp    short lzcat    ; CL and AH are critical
        ; ---------------

 mshen: test   ch, ch         ; CMPNTQ CH, 0
        jne    short lzdog
        mov    bl, 1
 lzdog: add    cl, bl
        inc    edx

 lzcat: mov    bh, ah
        mov    bl, [edx]      ; BOOM !!!
        mov    ch, bl
        and    ch, 128
        and    bl, 127        ; Nevertheless ...
        add    ah, bl
        cmp    al, ah
        jae    short mshen
        test   ch, ch         ; CMPNTQ CH, 0
        je     short lzhen
        add    cl, al         ; ADD Al (Al-Quaeda) to Cl (Chlorum)
        sub    cl, bh
 lzhen: bts    edi, ecx       ; 3 Byte's

        pope   edx
        pope   ecx
        loop   mscat          ; LODSB

        mov    [out0], edi

        ; pope   edi
        ; pope   esi
        ; pope   ebx
    


At the occasion of brewing my fascinating app that I'll release when it's ready, I encountered this interesting function.

2. find out what useful it is supposed to do
3. guess what the app could be about
4. optimize it
5. port it to C+++ , compile , measure bloat and compare with my FASM version

PS:

http://board.flatassembler.net/topic.php?t=13749
http://board.flatassembler.net/topic.php?t=11044
http://board.flatassembler.net/topic.php?t=10874
http://board.flatassembler.net/topic.php?t=9016
http://board.flatassembler.net/topic.php?t=2164

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 10 Aug 2013, 08:24
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4043
Location: vpcmpistri
bitRAKE 10 Aug 2013, 23:56
2) Corral the animals?

3) Wire mesh calibration?

4a) Instead of masking out the top bit of CH, the jCC can be changed to use the sign bit of the flag register.

5) No thank you.

Wink

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 10 Aug 2013, 23:56
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4043
Location: vpcmpistri
bitRAKE 11 Aug 2013, 20:22
2) I don't quite have a clue, yet...

4b) BTS only uses the bits required for the register size. MOV CL,31 can be changed to any number which has the least five bits set. So, if we choose MOV CL,-1 then further along MOV CL,0 can be changed to INC ECX -- saving a byte.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 11 Aug 2013, 20:22
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4043
Location: vpcmpistri
bitRAKE 11 Aug 2013, 20:50
4c) If the role of CH and AH are swapped, then SAHF can be used to test for high bit -- that'll save a couple bytes - replacing both TEST CH,CH. (The condition changes in (4a) will remain unchanged.) This doesn't conflict with (4b) because CMP AL,32 is the same number of bytes as CMP AL,CH; and MOV CH,32 can follow INC ECX.

Looks like six bytes so far...
Post 11 Aug 2013, 20:50
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386 19 Aug 2013, 11:58
Interesting ... your optimizations could be valid ... but 2) is still unresolved Wink
Post 19 Aug 2013, 11:58
View user's profile Send private message Reply with quote
quirck



Joined: 18 Aug 2013
Posts: 5
quirck 19 Aug 2013, 16:23
My wild guess... Looks like it checks whether certain symbols are present in the string pointed to by [in0] of length [in1]. As a result, in [out0]:
bit 0 is set whenever the string contains a space;
bit 1 is for symbols in range '!' .. '*';
bit 2 is for '+';
bit 3 is for ',';
bit 4 is for '-';
bit 5 is for '.';
bit 6 is for '/';
bit 7 is for digits;
bit 8 is for symbols in range ':'..'@';
bit 9 is for uppercase letters;
bit 10 indicates presence of '[';
bit 11 is for '\';
bit 12 is for ']';
bit 13 is for '^';
bit 14 is for '_' or '`';
bit 15 is for lowercase letters;
bit 16 is for symbols in range '{'..'~';
bits 17-30 are zero;
bit 31 indicates that the string contains symbols outside the range ' '..'~'
Post 19 Aug 2013, 16:23
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386 19 Aug 2013, 16:31
quirck wrote:
My wild guess... Looks like it checks whether certain symbols are present in the string


Welcome to the FASM forum Smile and congratulations ... you are the WINNER of this challenge Smile

PS: "3. guess what the app could be about" is still unresolved

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 19 Aug 2013, 16:31
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 08 Sep 2013, 19:14
Quote:
3. guess what the app could be about

Is it for a data compression/decompression utility?
Post 08 Sep 2013, 19:14
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386 10 Sep 2013, 08:58
> Is it for a data compression/decompression

no
Post 10 Sep 2013, 08:58
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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 cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.