NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: puttyios on June 16, 2012, 12:55:19 PM
-
I have the c code here:
#include <stdio.h>
9
10 int main(void)
11 {
12 int w, x, y, z;
13
14 printf("Enter two integers: ");
15 scanf("%i %i", &w, &x);
16 y = w + x;
17 z = w - x;
18 printf("sum = %i, difference = %i\n", y, z);
19
20 return 0;
21 }
and I write the assembly code , a part is below :
38 movl w(%rbp), %esi # y = w
39 addl x(%rbp), %esi # y += x
45 movl w(%rbp), %edx # z = w
46 subl x(%rbp), %edx # z -= x
my question is : "w(%rbp)" is corresponding to the 'w' local variable?
-
Yeah, I guess. I ASSume "w" and "x" are defined somewhere? Possibly something like:
.equ w -8
.equ x -16
or some such... I'm not sure about 64-bit code... might be some alignment padding added(?). What happens if the pesky user enters "xyz"?
Best,
Frank
-
is this 'x' 'w' defined as global variable or local ?
-
'x' and 'w' are just numbers (constants, not variables). They're used as offsets from rbp to locate "local" ("stack" or "automatic") variables.
Best,
Frank
-
thank you Frank!
I got that!
Best Regard!