Assembly language > Assembly discussions

I suppose...

(1/3) > >>

Jokaste:
Tell me if I am right, the ghosts you can answer too.
 

--- Code: ---
       mov  [hWndSysInput+rip],rcx
       mov  rdx,[hInstance+rip]
       xor  rax,rax
       mov  [rsp + 64],rcx
       mov  [rsp + 80],rdx
       mov  [rsp + 88],rax
       mov  [rsp + 72],rax
       mov  [rsp + 56],rax
       mov  [rsp + 48],rax
       mov  [rsp + 40],rax
       mov  [rsp + 32],rax
       mov  r9,WS_CHILD or LVS_NOSORTHEADER or LVS_SORTASCENDING or LVS_REPORT
       mov  r8,OFFSET szNullString
       mov  rdx,OFFSET WC_LISTVIEW
       xor  rcx,rcx
       call CreateWindowExA

--- End code ---

If I have well understood Agner Fog and others this must execute like this:
 

--- Code: ---ov  [hWndSysInput+rip],rcx     mov rdx,[hInstance+rip]                 NO PENALTY
xor  rax,rax                    mov [rsp + 64],rcx                      PENALTY because XOR is quicker than MOV
mov  [rsp + 80],rdx             mov [rsp + 88],rax                      NO PENALTY
mov  [rsp + 72],rax             mov [rsp + 56],rax                      NO PENALTY
mov  [rsp + 48],rax             mov [rsp + 40],rax                      NO PENALTY
mov  [rsp + 32],rax             mov r9,WS_CHILD or LVS_NOSORTHEADER     PENALTY cause of 1st instruction
mov  r8,OFFSET szNullString     mov rdx,OFFSET WC_LISTVIEW              NO PENALTY
xor  rcx,rcx                                                            PENALTY because the CALL cannot be excuted in the same cycle as the XOR
call CreateWindowExA                                                    PENALTY

--- End code ---

this could be improved:
 

--- Code: ---mov  [hWndSysInput+rip],rcx     mov  rdx,[hInstance+rip]
mov  [rsp + 64],rcx             mov  [rsp + 80],rdx
xor  rax,rax                    xor  rcx,rcx
mov  r8,OFFSET szNullString     mov  rdx,OFFSET WC_LISTVIEW
mov  [rsp + 88],rax             mov  [rsp + 72],rax
mov  [rsp + 56],rax             mov  [rsp + 48],rax
mov  [rsp + 40],rax             mov  [rsp + 32],rax
mov  r9,WS_CHILD or LVS_NO..    xchg rax,rax (NOP)
call CreateWindowExA

--- End code ---

And the final code is:
 

--- Code: ---mov  [hWndSysInput+rip],rcx
mov  rdx,[hInstance+rip]
mov  [rsp + 64],rcx
mov  [rsp + 80],rdx
xor  rax,rax
xor  rcx,rcx
mov  r8,OFFSET szNullString
mov  rdx,OFFSET WC_LISTVIEW
mov  [rsp + 88],rax
mov  [rsp + 72],rax
mov  [rsp + 56],rax
mov  [rsp + 48],rax
mov  [rsp + 40],rax
mov  [rsp + 32],rax
mov  r9,WS_CHILD or LVS_NOSORTHEADER or LVS_SORTASCENDING or LVS_REPORT
xchg rax,rax (NOP)
call CreateWindowExA

--- End code ---

Give me advice about this kind of parallel code.
Thanks
 
Jokaste / Grincheux
 

jj2007:

--- Quote from: Jokaste on October 28, 2017, 07:30:47 PM ---xor  rax,rax                    mov [rsp + 64],rcx                      PENALTY because XOR is quicker than MOV
--- End quote ---

Launch a debugger and try this:

--- Code: ---  int 3
  or rax, -1
  xor eax, eax
  or rax, -1
  xor rax, rax
--- End code ---

No idea whether xor eax, eax is any faster or slower than xor rax, rax, but it is one byte shorter and does the same.

Jokaste:
Thanks that's the kind of code I am looking for.
I have found that constant are not good for an assembler program because if they have the value the assembler codes them in the same way as they were greather than 0.
MOV RAX,SH_HIDE = MOV RAX,0 rather than XOR RAX,RAX
I would like to create a pdf with all the tricks experienced programmers have.
Yestirday I dowloaded MasmBasic and tryed to read what the editor displays... I stopped before the end, this program really is rich.

Jokaste:

--- Code: ---MOV RAX,00BADF00DBADCAFE                    ;RAX=00BADF00DBADCAFE
OR EAX,-1                                   ;RAX=00000000FFFFFFFF
MOV RAX,0BADF00DBADCAFEh                    ;RAX=00BADF00DBADCAFE
OR  RAX,-1                                  ;RAX=FFFFFFFFFFFFFFFF

--- End code ---

jj2007:

--- Quote from: Jokaste on October 29, 2017, 03:46:51 PM ---I have found that constant are not good for an assembler program because if they have the value the assembler codes them in the same way as they were greather than 0.
MOV RAX,SH_HIDE = MOV RAX,0 rather than XOR RAX,RAX
--- End quote ---

Sometimes I use conditional assembly to decide which instruction to take:

--- Code: --- if (IMAGE_ICON-IMAGE_BITMAP) eq 1
inc edi
else
add edi, IMAGE_ICON-IMAGE_BITMAP
endif
--- End code ---

In this case, it is not really necessary because IMAGE_ICON and IMAGE_BITMAP are Windows constants that will never change IMHO, so it will be inc edi, always. But in this excerpt from the For_ ... Next macro, it saves a few bytes (MasmBasic.inc, lines 9719ff):
--- Code: --- ifdifi tmpReg, vtS$
if atVt eq atImmediate
ife vtS$
xor tmpReg, tmpReg
elseif vtS$ eq -1
or tmpReg, -1
elseif (vtS$ le 127) and (vtS$ ge -128)
push vtS$
pop tmpReg
else
mov tmpReg, vtS$
endif
else
mov tmpReg, vtS$
endif
endif
--- End code ---


--- Quote ---Yestirday I dowloaded MasmBasic and tryed to read what the editor displays... I stopped before the end, this program really is rich.
--- End quote ---

Thanks ;)

Navigation

[0] Message Index

[#] Next page

Go to full version