3

I am slightly confused by some x86_64 linux code here (generated by llvm):

# BB#0:                                 # %entry
    push    RBP
.Ltmp21:
    .cfi_def_cfa_offset 16
.Ltmp22:
    .cfi_offset rbp, -16
    mov RBP, RSP
.Ltmp23:
    .cfi_def_cfa_register rbp
    push    RBX
    push    RAX
.Ltmp24:
    .cfi_offset rbx, -24
    mov EDI, .L.urandom
    mov ESI, 8
    call    open
    mov EBX, EAX
    mov EDI, EBX
    mov ESI, ptrenc.keys
    mov EDX, 16
    call    read

From what I read in wikipedia, I would have expected the arguments to open and read to be passed in R-Registers (RDI, RSI, RDX).

The code uses the 64-bit Registers to build the stack frame. Why does it use the 32-bit registers for the calls?

1

2 Answers 2

3

So, your question is mainly about this part of the code (if I do not care about the second call which is similar anyway):

mov EDI, .L.urandom
mov ESI, 8
call    open

In fact, this is perfectly okay to go through ESI and EDI as it is done here, because the value that are transfered are 32 bits values... and, anyway, in amd64, when manipulating 32 bits registers you will blank the upper 32 bits of the corresponding 64 bits registers (zero-extended). So, you end-up with RSI and RDI which are containing the right values and you only had to transfer 32 bits from the memory to the registers... It may be seen as a small optimization.

-2

You'll find an answer in here. If you want more details, well, here you'll find everything you need.

5
  • 9
    Please don't post just links. Try to quote the relevant parts in the answer. P.S. your links don't seem to actually answer the question.
    – Igor Skochinsky
    Sep 29, 2014 at 13:27
  • Well, the purpose is not to idiotically answer the question, rather to make a point. There's no need to ask a question for which there's already an answer in the documentation. Plus, the links answer the question perfectly, all you have to do is look !
    – yaspr
    Sep 30, 2014 at 9:15
  • 2
    @yaspr: "Idiotically answer the question..." What on earth is idiotic about answering the question, as you're suppose to be doing on the SE?
    – JamalS
    Sep 30, 2014 at 9:25
  • As I said in my previous comment : The answer is in the documentation ! Redundancy, that's idiotic.
    – yaspr
    Oct 1, 2014 at 13:40
  • Sometimes the URLs people use to link to the documentation go dead, so it's best to provide a summary of what the documentation actually says. (And it can take a fair bit of work to actually work out the implications of the documentation, too...)
    – SamB
    Apr 5, 2017 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.