How many ways to set a register to zero?

前端 未结 8 1070
有刺的猬
有刺的猬 2020-12-02 17:00

I\'m curious how many ways are there to set a register to zero in x86 assembly. Using one instruction. Someone told me that he managed to find at least 10 ways to do it.

相关标签:
8条回答
  • 2020-12-02 17:58
    mov eax,0  
    shl eax,32  
    shr eax,32  
    imul eax,0 
    sub eax,eax 
    xor eax,eax   
    and eax,0  
    andn eax,eax,eax 
    
    loop $ ;ecx only  
    pause  ;ecx only (pause="rep nop" or better="rep xchg eax,eax")
    
    ;twogether:  
    push dword 0    
    pop eax
    
    or eax,0xFFFFFFFF  
    not eax
    
    xor al,al ;("mov al,0","sub al,al",...)  
    movzx eax,al
    ...
    
    0 讨论(0)
  • 2020-12-02 17:59

    You can set register CX to 0 with LOOP $.

    0 讨论(0)
提交回复
热议问题