Do we really need movq $0x0, %rdx in Chapter 12?

Hi everyone,

I’m exploring StackWalkthrough function from Chapter 12, and cannot realize why do we need third instruction:

push %rbp ; Push contents of RBP onto the stack (*RSP = RBP, RSP decreases)
movq %rsp, %rbp ; RBP = RSP 
movq $0x0, %rdx ; RDX = 0 **<-- this one**
movq %rdi, %rdx ; RDX = RDI

As we change RDX register right after assigning it to zero… @lolgrep could you help?

Thanks in advance

@lolgrep Do you have any feedback on this? Thank you - much appreciated! :]

Hey @relex

The movq $0x0, %rdx ; instruction is a wasted one since it’s getting set in the next instruction. I chose to add this in so you could visually see what is happening and have you focus on RDX right before it gets set to 0x5

Great, thanks, @lolgrep!

So, I understood correctly and genereally speaking this instruction is unnecessary.

1 Like

This topic was automatically closed after 166 days. New replies are no longer allowed.