0
.section    .text

    .global mystery 
      
    .type mystery, @function

mystery: 

    pushl %ebp
    movl %esp, %ebp
    xorl %eax, %eax
    xorl %ecx, %ecx
    movl 8(%ebp), %edx

begin:

    cmpl 12(%ebp), %ecx
    jge done
    addl (%edx, %ecx, 4), %eax
    incl %ecx
    jmp begin

done: 

    movl %ebp, %esp
    popl %ebp
    ret

I am aware that there is a loop at begin: but I am not entirely sure what either of the xorl would do in this function.

fuz
  • 88,405
  • 25
  • 200
  • 352
Dpant2022
  • 1
  • 1
  • 2
    So you do understand the basic syntax and behaviour of xorl and only ask what they achieve in the larger context? You could clarify that by shortly desribing your understanding. – Yunnosch Nov 29 '22 at 09:35
  • 2
    `xor R, R` for any particular register `R` is the x86 idiom for clearing (setting to zero) that register. – unwind Nov 29 '22 at 09:49
  • Hello, I am aware of XOR which is exclusive or but I am not sure how it applies in assembly and I am not sure how it applies specifically within assembly code. From what I researched xorl is for clearing a register but I am not sure what purpose that holds to this assembly language. – Dpant2022 Nov 29 '22 at 13:37
  • @Dpant2022 xor is xor, assmbly or not. XORing a value with itself results in 0 by definition. I don't understand your question. `xorl %eax, %eax` clears the eax register. – Jabberwocky Nov 29 '22 at 13:38
  • @Jabberwocky so does it do the same thing as movl $0, %eax? – Dpant2022 Nov 29 '22 at 13:41
  • @Dpant2022 The purpose of `xorl %eax, %eax` is clearing the eax register. You could also use `movel $0,%eax` which does the same thing, but which is probably slightly slower and the opcode is most certainly larger. – Jabberwocky Nov 29 '22 at 13:42
  • XORing a register with itself sets it to 0, but faster than a mov 0 – AR7CORE Nov 29 '22 at 14:07

0 Answers0