Find the answer to your Linux question:
Results 1 to 5 of 5
I know assembly's used for making compilers and such, but not much else. Can anybody explain to me what exactly assembly is, and maybe a really in-depth tutorial on it? ...
  1. #1
    Just Joined!
    Join Date
    Nov 2010
    Location
    Alaska
    Posts
    55

    Assembly

    I know assembly's used for making compilers and such, but not much else. Can anybody explain to me what exactly assembly is, and maybe a really in-depth tutorial on it? Many thanks obliged.

    P.S. I have NASM and am running Knoppix Linux

  2. #2
    Just Joined!
    Join Date
    Apr 2011
    Posts
    19

    assembly is still used for many things

    Assembler is just one level lower than c. Its the machine language in symbolic form. I have on occasion found it useful to look at it when debugging looking for optimization problems in the compilers. Although compilers have gotten much better over the past decade or so, rarely generating problems. You can get a very good idea of what assembly is by compiling your c code into assembly instead of a final linked executable. Just do
    cc -S foo.c
    and a file called foo.s will be created which is the assembly code for the C you just compiled.
    Note that the assembler will be different for different machine architectures (sun, i86, i86-64) as assembler language is different for different machines. I imagine you could google for the actual instructions for i86 and get a listing. It is quite a rich instruction set. SPARC is a little smaller as it is a RISC (Reduced Instruction Set Computer) machine. I would encourage you to explore this as it helps programmers understand what's going on under the hood.

  3. #3
    Just Joined!
    Join Date
    Nov 2010
    Location
    Alaska
    Posts
    55
    Thank you for the long reply, it's exactly what I was looking for. Does the cc thing also work with c++?

    My compiler is g++ if it matters, and this is an i86 machine.

  4. #4
    Just Joined!
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    31
    Tutorial on 32 bit assembly language programming with NASM.

  5. #5
    Just Joined!
    Join Date
    Apr 2011
    Posts
    19

    Should work for c++

    I am pretty sure the -S option should work on c++ files. I don't know why it would not. Another thing you could try is to compile without -g, and then jump into gdb and set a breakpoint in a relatively simple function. Then stepi thru the function. You can examine registers etc. Another thing that you can do is to first print funcName where funcName is some function in your code. It will print an address. Then in gdb do
    x/20i 0x040404
    or whatever the address was. gdb will print the 1st 20 instructions. So the examine command is indispensable for assy debugging. Another useful thing to do while playing is the cpu registers can be quered with stuff like
    print $r9
    the "disassemble" command is also useful to disassemble the code at the current pc.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...