Skip to content

Instantly share code, notes, and snippets.

@israellot
Last active September 26, 2022 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save israellot/1cd1ee394dfeb1090e2333872149be53 to your computer and use it in GitHub Desktop.
Save israellot/1cd1ee394dfeb1090e2333872149be53 to your computer and use it in GitHub Desktop.
Example of pointer access with int vs uint
public static unsafe int PointerAccessInt(byte* ptr,int x,int y)
{
return ptr[x]& ptr[x+y];
}
public static unsafe int PointerAccessUInt(byte* ptr,uint x,uint y)
{
return ptr[x]& ptr[x+y];
}
/*
Program:PointerAccessInt(long,int,int):int:
movsxd rax, esi
movzx rax, byte ptr [rdi+rax]
add esi, edx
movsxd rsi, esi
movzx rdi, byte ptr [rsi+rdi]
and eax, edi
ret
Program:PointerAccessUInt(long,int,int):int:
mov eax, esi
movzx rax, byte ptr [rdi+rax]
add esi, edx
movzx rdi, byte ptr [rsi+rdi]
and eax, edi
ret
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment