Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

แปลงโค้ด C/C++ เป็น Assembly Language

ใช้ GCC ตัวเลือก -S เพื่อสร้าง Assembly Output

คำสั่ง

gcc -S program.cpp

ตัวอย่างโค้ด C++

#include <iostream>
using namespace std;
int main() {
    int x = 50, y = 60, sum;
    sum = x + y;
    cout << "Sum is: " << sum << endl;
}

Output (Assembly x86-64)

.file "test_cpp.cpp"
.text
.globl main
main:
    pushq %rbp
    movq %rsp, %rbp
    subq $16, %rsp
    movl $50, -12(%rbp)
    movl $60, -8(%rbp)
    movl -12(%rbp), %edx
    movl -8(%rbp), %eax
    addl %edx, %eax
    movl %eax, -4(%rbp)
    ... (โค้ดเรียก cout) ...
    ret