मैं उपरोक्त सी कोड के संबंध में इस असेंबली कोड को समझने की कोशिश कर रहा हूं। मुझे यकीन नहीं है कि मैं सही रास्ते पर हूं तो शायद कोई मुझे इस पर बेहतर समझने में मदद कर सकता है।असेंबली भाषा को समझना
int silly(int n, int *p)
{
int val, val2;
if (n > 0)
val2 = silly(n << 1, &val);
else
val = val2 = 0;
*p = val + val2 + n;
return val + val2;
}
यह निम्न मशीन कोड पैदावार:
silly:
pushl %ebp // Here I am making space for the function on the stack
movl %esp,%ebp // Moving the stack pointer where the base pointer is
subl $20,%esp // Subtracting 20 from the stack pointer to allocate more space
pushl %ebx // Pushing the %ebx register on top of the stack
movl 8(%ebp),%ebx // Getting the first argument(which is n) and store it in register %ebx
testl %ebx,%ebx // The first if-statement which compares if n > 0
jle .L3 // Jump if less or equal - meaning if n < 0 then jump to .L3
addl $-8,%esp // Add -8 to %esp to allocate more space
leal -4(%ebp),%eax // Storing the first local variable (which is val) in %eax
pushl %eax // Pushing the register %eax on top of the stack
leal (%ebx,%ebx),%eax // n + n and stores it as 2n in %eax
pushl %eax // Pushing register %eax on top of the stack (Which I find strange
// considering that I've just pushed %eax onto the stack above
call silly // Call the function silly
jmp .L4 // Jump to .L4 (Unconditionally)
.p2align 4,,7 // Don't know what this means.
.L3: // .L3 is the else-statement
xorl %eax,%eax // Basically making %eax = 0
movl %eax,-4(%ebp) // Moving the value in %eax which is 0 to the first local variable
// meaning val = 0
.L4: // .L4 is the section after the else-statement
movl -4(%ebp),%edx // Getting val again and now storing it in %edx
addl %eax,%edx // Adding what is in %eax (which is 0) to %edx
movl 12(%ebp),%eax // Getting the second parameter (*p) and storing it in %eax
addl %edx,%ebx // Adding value from %edx to %ebx - meaning val + n
movl %ebx,(%eax) // Moving what is in %ebx and storing it in memory location of %eax
movl -24(%ebp),%ebx // Getting the second local variable (val2) and moving it to %ebx
movl %edx,%eax // Move val to %eax - and the return value will be in %eax
movl %ebp,%esp
popl %ebp
ret
मैं इस के आसपास मेरे सिर लपेटो करने की कोशिश कर रहा हूँ और मैं सिर्फ विधानसभा के बारे में सोच तो इस विषय पर संकेत वास्तव में अच्छा होगा शुरू कर दिया है।
(एक) अलग-अलग वैल ढेर पर संग्रहीत है: मैं सवाल मैं इस विधानसभा कोड है जो ढेर की मेरी समझ में मदद कर सकता के बारे में पूछने की जरूरत है की एक जोड़ी है?
(बी) यदि हां, तो क्या बाइट ओसेट (% ebp के सापेक्ष) पर यह संग्रहीत है?
(सी) इसे ढेर पर स्टोर करना क्यों जरूरी है?(ए) क्या वैरिएबल वैल 2 स्टैक पर संग्रहीत है?
(बी) यदि हां, तो क्या बाइट ओसेट (% ebp के सापेक्ष) पर यह संग्रहीत है?
(सी) इसे ढेर पर स्टोर करना क्यों जरूरी है?(ए) क्या (यदि कुछ भी) -24 (% ईबीपी) पर संग्रहीत किया जाता है?
(बी) अगर वहां कुछ संग्रहीत किया जाता है, तो इसे स्टोर करना क्यों आवश्यक है?(ए) क्या (यदि कुछ भी) -8 (% ईबीपी) पर संग्रहीत किया जाता है?
(बी) अगर वहां कुछ संग्रहीत किया जाता है, तो इसे स्टोर करना क्यों आवश्यक है?
अग्रिम :)
आपका प्रश्न वास्तव में क्या है? – o11c
मैंने अभी प्रश्न को अद्यतन किया है। क्षमा करें :) – drleifz
नोट: 'val2' अनियंत्रित है। कभी-कभी। और कभी-कभी 'वाल' भी होता है। – wildplasser