Ở đây ta xem cách tạo output Assembly từ mã nguồn C/C++ dùng gcc.
GCC cung cấp tùy chọn -S để lấy output assembler. Option này hiển thị output sau biên dịch, trước khi gửi assembler.
gcc -S program.cpp
Xem output dạng như thế nào với chương trình đơn giản: lưu 2 số vào x, y, tính tổng, in ra.
Ví dụ
#include <iostream>
using namespace std;
int main() {
int x = 50, y = 60, sum;
sum = x + y;
cout << "Sum is: " << sum << endl;
return 0;
}
Kết quả (Assembly x86_64)
.file "test_cpp.cpp" .text .section .rodata ... main: .LFB1493: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 ... movl $50, -12(%rbp) movl $60, -8(%rbp) movl -12(%rbp), %edx movl -8(%rbp), %eax addl %edx, %eax movl %eax, -4(%rbp) ... call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT ... ret .cfi_endproc ...