Original C program
#include <stdint.h> struct point3D { int16_t x ; int16_t y ; int16_t z ; } ; struct point3D gStruct ; int16_t gVect[100] ; void asmExample(int i, int16_t pVect[], struct point3D *pStruct) { pVect[i] = gVect[i] ; gVect[i+1] = pVect[i+1] ; pStruct->y = gStruct.y ; gStruct.z = pStruct->z ; }
Assembly generated by the C compiler with no optimization
This example has no optimization. Also, several comments have been added to clariy the program.
;;; For register ax ;;; rax -- 64-bit register ;;; eax -- lower 32-bits ;;; ax -- lower 16-bits .file "asmExample.c" ;;; space for global variables .comm gStruct,6,2 .comm gVect,200,32 .text .globl asmExample .type asmExample, @function asmExample: .LFB0: .cfi_startproc ;;; storing parameters on stack frame pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 ;;; i at -4(%rbp) movl %edi, -4(%rbp) ;;; pVect at -16(%rbp) movq %rsi, -16(%rbp) ;;; pStruct at -24(%rbp) movq %rdx, -24(%rbp) ;;; pVect[i] = gVect[i] ; movl -4(%rbp), %eax cltq addq %rax, %rax addq -16(%rbp), %rax movl -4(%rbp), %edx movslq %edx, %rdx movzwl gVect(%rdx,%rdx), %edx movw %dx, (%rax) ;;; gVect[i+1] = pVect[i+1] ; movl -4(%rbp), %eax leal 1(%rax), %ecx movl -4(%rbp), %eax cltq addq $1, %rax addq %rax, %rax addq -16(%rbp), %rax movzwl (%rax), %edx movslq %ecx, %rax movw %dx, gVect(%rax,%rax) ;;; pStruct->y = gStruct.y ; movzwl gStruct+2(%rip), %edx movq -24(%rbp), %rax movw %dx, 2(%rax) ;;; gStruct.z = pStruct->z ; movq -24(%rbp), %rax movzwl 4(%rax), %eax movw %ax, gStruct+4(%rip) leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE0: .size asmExample, .-asmExample .ident "GCC: (GNU) 4.4.7 20120313 (Red Hat 4.4.7-3)" .section .note.GNU-stack,"",@progbits
Assembly generated by the C compiler with optimization level 2
.file "asmExample.c" .text .p2align 4,,15 .globl asmExample .type asmExample, @function asmExample: .LFB0: .cfi_startproc ;;; i in %edi ;;; pVect in %rsi ;;; gVect in %rdx ;;; pVect[i] = gVect[i] ; ;;; gVect[i+1] = pVect[i+1] ; ;;; %rax := i movslq %edi, %rax ;;; %edi := i+1 addl $1, %edi ;;; %ecx := gVect[i] movzwl gVect(%rax,%rax), %ecx ;;; %rdi := i+1 movslq %edi, %rdi ;;; pVect[i] := gVect[i] movw %cx, (%rsi,%rax,2) ;;; %eax := pVect[1+1] movzwl 2(%rsi,%rax,2), %eax ;;; gVect[i+1] := pVect[1+1] movw %ax, gVect(%rdi,%rdi) ;;; pStruct->y = gStruct.y ; movzwl gStruct+2(%rip), %eax movw %ax, 2(%rdx) ;;; gStruct.z = pStruct->z ; movzwl 4(%rdx), %eax movw %ax, gStruct+4(%rip) ret .cfi_endproc .LFE0: .size asmExample, .-asmExample .comm gStruct,6,2 .comm gVect,200,32 .ident "GCC: (GNU) 4.4.7 20120313 (Red Hat 4.4.7-3)" .section .note.GNU-stack,"",@progbits
If you really want more detail, particularly about try the Cocoa Factory’s X64_64 Assembly Language Tutorial or Intel’s Introduction to x64 Assembly.