Skip to content

Instantly share code, notes, and snippets.

@aktau
Last active August 29, 2015 14:00
Show Gist options
  • Save aktau/11220937 to your computer and use it in GitHub Desktop.
Save aktau/11220937 to your computer and use it in GitHub Desktop.
Which part of the register is used?
.section __TEXT,__text,regular,pure_instructions
.globl _main
.align 4, 0x90
_main: ## @main
.cfi_startproc
## BB#0:
pushq %rbp
Ltmp2:
.cfi_def_cfa_offset 16
Ltmp3:
.cfi_offset %rbp, -16
movq %rsp, %rbp
Ltmp4:
.cfi_def_cfa_register %rbp
movl $0, -4(%rbp)
movl $15, -8(%rbp)
movl $20, -12(%rbp)
movl -8(%rbp), %eax
imull -12(%rbp), %eax
movl %eax, -16(%rbp)
movl -16(%rbp), %eax
popq %rbp
ret
.cfi_endproc
.subsections_via_symbols
.section __TEXT,__text,regular,pure_instructions
.globl _main
.align 4, 0x90
_main: ## @main
.cfi_startproc
## BB#0:
pushq %rbp
Ltmp2:
.cfi_def_cfa_offset 16
Ltmp3:
.cfi_offset %rbp, -16
movq %rsp, %rbp
Ltmp4:
.cfi_def_cfa_register %rbp
movl $0, -4(%rbp)
movq $15, -16(%rbp)
movq $20, -24(%rbp)
movq -16(%rbp), %rax
imulq -24(%rbp), %rax
movq %rax, -32(%rbp)
movq -32(%rbp), %rax
movl %eax, %ecx
movl %ecx, %eax
popq %rbp
ret
.cfi_endproc
.subsections_via_symbols
/**
* compile to asm and view with:
*
* cc -DTYPE=size_t register.c -S -o register.s && vim register.s
* cc -DTYPE=int register.c -S -o register.s && vim register.s
*/
#include <stdio.h>
#include <stdint.h>
typedef TYPE int_t;
int main() {
int_t i = 15;
int_t m = 20;
int_t a = i * m;
return a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment