Issue storing a byte into a register x86-64 assembly

前端 未结 1 1355
暗喜
暗喜 2021-01-07 12:15

I am trying to write a function that determines the length of a string given as the first argument, so %rdi will contain char *ptr. When I call movb (%rdi),%rcx

相关标签:
1条回答
  • 2021-01-07 12:36

    All the general-purpose registers have the low 8 bits separately addressable as al, bl, cl, dl, sil, dil, bpl, spl, r8b through r15b (intel documentation uses l suffix). In addition, a few have bits 8..15 also addressable, namely ah, bh, ch and dh.

    So if you only want to load a byte, you can use one of the above. Alternatively, you can use zero- or sign-extension to widen the byte data, for example in your case movzbl (%rdi), %ecx (read: move zero extended byte to long). Note that operating on 32 bit registers zeroes the top 32 bits of the "parent" 64 bit register, but operating on 8 or 16 bit sub-registers leaves the rest of the bits unchanged.

    I feel you should probably (re-)read the basic architecture section of the intel manuals.

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