lolzwut
January 5th, 2010, 03:00 PM
Hi,
I have a HP G60 Notebook and I'm running Ubuntu 9.04 dual-booted with Windows Vista Home Premium. I just started learning Assembly from some online tutorial, I have basically no knowledge of Assembly. I'm not even sure which one I'm programming in, but I know that the registers I've been learning about are the ones that start with e (eax, ebx, ecx, edx, esi etc.). Anyway in order to understand how to use gdb they said to disassemble this C program:
#include<stdio.h>
#include<stdlib.h>
int add(int x, int y)
{
int z =10;
z = x + y;
return z;
}
main(int argc, char **argv)
{
int a = atoi(argv[1]);
int b = atoi(argv[2]);
int c;
char buffer[100];
gets(buffer);
puts(buffer);
c = add(a,b);
printf("Sum of %d+%d = %d\n",a, b, c);
exit(0);
}
so I did
me@ubuntu: ~$ gdb ./SimpleDemo
(gdb): disassemble main
then the output I got was:
0x0000000000400676 <main+0>: push %rbp
0x0000000000400677 <main+1>: mov %rsp,%rbp
0x000000000040067a <main+4>: push %rbx
0x000000000040067b <main+5>: sub $0x98,%rsp
0x0000000000400682 <main+12>: mov %edi,-0x94(%rbp)
0x0000000000400688 <main+18>: mov %rsi,-0xa0(%rbp)
0x000000000040068f <main+25>: mov %fs:0x28,%rax
0x0000000000400698 <main+34>: mov %rax,-0x18(%rbp)
0x000000000040069c <main+38>: xor %eax,%eax
0x000000000040069e <main+40>: mov -0xa0(%rbp),%rax
0x00000000004006a5 <main+47>: add $0x8,%rax
0x00000000004006a9 <main+51>: mov (%rax),%rax
0x00000000004006ac <main+54>: mov %rax,%rdi
0x00000000004006af <main+57>: callq 0x400548 <atoi@plt>
0x00000000004006b4 <main+62>: mov %eax,-0x84(%rbp)
0x00000000004006ba <main+68>: mov -0xa0(%rbp),%rax
0x00000000004006c1 <main+75>: add $0x10,%rax
0x00000000004006c5 <main+79>: mov (%rax),%rax
0x00000000004006c8 <main+82>: mov %rax,%rdi
0x00000000004006cb <main+85>: callq 0x400548 <atoi@plt>
0x00000000004006d0 <main+90>: mov %eax,-0x88(%rbp)
0x00000000004006d6 <main+96>: lea -0x80(%rbp),%rax
---Type <return> to continue, or q <return> to quit---gdb ./SimpleDemo
Why are the registers %rax %rdp and stuff? What type of Assembly does Ubuntu even have? I know there's Intel and AT&T syntax but I don't know how to recognize it and I don't know anything about this or why the registers are different. Can someone tell me what ASM the kernel runs? Also can I still program with the regular registers that I'm familiar with? Or will that not work? Thanks.
I have a HP G60 Notebook and I'm running Ubuntu 9.04 dual-booted with Windows Vista Home Premium. I just started learning Assembly from some online tutorial, I have basically no knowledge of Assembly. I'm not even sure which one I'm programming in, but I know that the registers I've been learning about are the ones that start with e (eax, ebx, ecx, edx, esi etc.). Anyway in order to understand how to use gdb they said to disassemble this C program:
#include<stdio.h>
#include<stdlib.h>
int add(int x, int y)
{
int z =10;
z = x + y;
return z;
}
main(int argc, char **argv)
{
int a = atoi(argv[1]);
int b = atoi(argv[2]);
int c;
char buffer[100];
gets(buffer);
puts(buffer);
c = add(a,b);
printf("Sum of %d+%d = %d\n",a, b, c);
exit(0);
}
so I did
me@ubuntu: ~$ gdb ./SimpleDemo
(gdb): disassemble main
then the output I got was:
0x0000000000400676 <main+0>: push %rbp
0x0000000000400677 <main+1>: mov %rsp,%rbp
0x000000000040067a <main+4>: push %rbx
0x000000000040067b <main+5>: sub $0x98,%rsp
0x0000000000400682 <main+12>: mov %edi,-0x94(%rbp)
0x0000000000400688 <main+18>: mov %rsi,-0xa0(%rbp)
0x000000000040068f <main+25>: mov %fs:0x28,%rax
0x0000000000400698 <main+34>: mov %rax,-0x18(%rbp)
0x000000000040069c <main+38>: xor %eax,%eax
0x000000000040069e <main+40>: mov -0xa0(%rbp),%rax
0x00000000004006a5 <main+47>: add $0x8,%rax
0x00000000004006a9 <main+51>: mov (%rax),%rax
0x00000000004006ac <main+54>: mov %rax,%rdi
0x00000000004006af <main+57>: callq 0x400548 <atoi@plt>
0x00000000004006b4 <main+62>: mov %eax,-0x84(%rbp)
0x00000000004006ba <main+68>: mov -0xa0(%rbp),%rax
0x00000000004006c1 <main+75>: add $0x10,%rax
0x00000000004006c5 <main+79>: mov (%rax),%rax
0x00000000004006c8 <main+82>: mov %rax,%rdi
0x00000000004006cb <main+85>: callq 0x400548 <atoi@plt>
0x00000000004006d0 <main+90>: mov %eax,-0x88(%rbp)
0x00000000004006d6 <main+96>: lea -0x80(%rbp),%rax
---Type <return> to continue, or q <return> to quit---gdb ./SimpleDemo
Why are the registers %rax %rdp and stuff? What type of Assembly does Ubuntu even have? I know there's Intel and AT&T syntax but I don't know how to recognize it and I don't know anything about this or why the registers are different. Can someone tell me what ASM the kernel runs? Also can I still program with the regular registers that I'm familiar with? Or will that not work? Thanks.