In-Line Assembly Solution (C/C++)


  • 0

    Uses the add instruction.

    class Solution {
    public:
        int getSum(int a, int b) {
            int res;
            __asm__("addl %1, %2\nmovl %2, %0\n" : "=r"(res) : "r" (a), "r" (b));
            return res;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.