Skip to content

Instantly share code, notes, and snippets.

@EduardoRFS
Last active September 20, 2020 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save EduardoRFS/dfe620449a7e97dccacee20750163127 to your computer and use it in GitHub Desktop.
Save EduardoRFS/dfe620449a7e97dccacee20750163127 to your computer and use it in GitHub Desktop.
/*
your obj pointer came in the first position of the stack
so you will load it on a register
*/
movl (%esp), %eax ;
/*
then you want to do obj.a += 6, if we suppose
that we're talking about records not dictionaries
and we know that obj.a is on position 4
on x86 you can do
*/
addl $6, 4(%eax) ;
/*
internally this is what is happening, but atomically
so the cost of indirection is the same as if it was passed by value
because the only reference to the object is the first mov
*/
movl 4(%eax), %ebx ; /* load */
addl $6, %ebx ; /* op */
movl %ebx, 4(%eax) /* store */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment