Skip to content

Instantly share code, notes, and snippets.

@gtkatakura
Forked from EduardoRFS/val+ref.as
Created September 20, 2020 03:53
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 gtkatakura/b6d8d13ee7f248e03a3124c340d2b106 to your computer and use it in GitHub Desktop.
Save gtkatakura/b6d8d13ee7f248e03a3124c340d2b106 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