|
|
 |
11-03-2012, 10:24 PM
|
#1
|
|
Senior Member
Join Date: Nov 2011
Posts: 258
|
assembly code
So, I understand registers, base/stack pointers, and the instructions. I can sort of walk through a program and somewhat tell what it is doing. But I have a terrible time translating this in to another language, like C.
Any advice?
Also, I have been using GDB to debug, is there a better debugger that will disassemble?
|
|
|
11-03-2012, 10:27 PM
|
#2
|
|
Lifer
Join Date: Jun 2000
Posts: 11,641
|
Might be better to start looking at it from the other direction. Write a simple method in C, compile it, and look at it in an Assembler. Sometimes the stuff the compiler comes up with will surprise you, and totally give you a different perspective.
Try a recursive function, and watch how the assembly uses a stack to trace its steps up and down the function calls.
__________________
.
|
|
|
11-03-2012, 10:47 PM
|
#3
|
|
Golden Member
Join Date: Mar 2008
Posts: 1,389
|
Write more C; over time, you'll start to see the assembly pretty easily through the veneer of C, but only practice will get you there.
|
|
|
11-03-2012, 11:25 PM
|
#4
|
|
Elite Member
Join Date: Dec 1999
Location: Colorado
Posts: 7,323
|
Try compiling your C code with gcc -S. That outputs the assembly code equivalent.
__________________
Look for really BIG primes with TeAm AnandTech PrimeGrid! 
Next race: June 14-17
vBulletin looking run down? Get your script fix here.
|
|
|
11-04-2012, 02:10 AM
|
#5
|
|
Diamond Member
Join Date: Mar 2006
Location: San Gabriel, California
Posts: 5,202
|
*Shudder* Assembly...that stuff gave me nightmares, yo! I never learned C either, it was just killing me.
__________________
Rig Heat
Quote:
Originally posted by: Toastedlightly
shes shorter than my c*ck.
Does she work in a circus? Because I've never seen a 2 inch woman before.
AnandTech Moderator
|
|
|
|
11-04-2012, 02:50 AM
|
#6
|
|
Senior Member
Join Date: Apr 2005
Posts: 652
|
Learning assembly is useful for specific optimization (think SSE or other vector instructions if you don't like x86-64). If you need to deal with base/stack pointers you are likely coding in the wrong decade.
|
|
|
11-04-2012, 10:28 AM
|
#7
|
|
Golden Member
Join Date: Mar 2008
Posts: 1,389
|
Quote:
Originally Posted by lambchops511
Learning assembly is useful for specific optimization (think SSE or other vector instructions if you don't like x86-64). If you need to deal with base/stack pointers you are likely coding in the wrong decade.
|
Don't let the naive dissuade you, OP:
- There's a huge value in understanding the machine at the level of base and stack pointers;
- Similarly large value in understanding how high-level languages map to assembly-level constructs;
- Not all platforms afford the luxury of high-level execution environments;
- Programmers write compilers, don't they?
|
|
|
11-04-2012, 06:54 PM
|
#8
|
|
Diamond Member
Join Date: Jul 2006
Location: Raleigh, NC
Posts: 3,934
|
Quote:
Originally Posted by degibson
Don't let the naive dissuade you, OP:
- There's a huge value in understanding the machine at the level of base and stack pointers;
- Similarly large value in understanding how high-level languages map to assembly-level constructs;
- Not all platforms afford the luxury of high-level execution environments;
- Programmers write compilers, don't they?
|
I very much agree, I personally think that a knowledge of how the code you write will be translated into assembly (at least at some level) is critical. Then again the higher-level language you work in, the less critical this may be, however I love embedded/systems programming, so I can't imagine _not_ understanding code at this level.
|
|
|
11-04-2012, 08:58 PM
|
#9
|
|
Lifer
Join Date: Jan 2004
Posts: 10,722
|
Use a IDE that shows interleaved C and corresponding assembly output during debug tracing/stepping. Disable optimizations. Have fun discovering that there are really only a handful of constructs that keep occurring over and over again in assembly (conditionals, for loops, do/while loops, etc).
When you work in pure assembly, you'll naturally learn to comment everything and all the comments end up actually looking like an entire pseudo C program.
My current platform of interest is the 6502 / NES. Very unique and challenging platform.
Some excerpts:
http://forums.anandtech.com/showthread.php?t=2271963
Last edited by exdeath; 11-04-2012 at 09:03 PM.
|
|
|
11-04-2012, 09:06 PM
|
#10
|
|
Lifer
Join Date: Jan 2004
Posts: 10,722
|
Quote:
Originally Posted by degibson
Don't let the naive dissuade you, OP:
- There's a huge value in understanding the machine at the level of base and stack pointers;
- Similarly large value in understanding how high-level languages map to assembly-level constructs;
- Not all platforms afford the luxury of high-level execution environments;
- Programmers write compilers, don't they?
|
WHAT? You mean I can't have Java on a system with 2k of RAM?! What do you mean I need 2 GB RAM just to write "Hello World!" ?
|
|
|
11-05-2012, 07:24 PM
|
#11
|
|
Golden Member
Join Date: Mar 2008
Posts: 1,389
|
2k will get you just to your HelloWorldFactory 
But in 4k, you can do this: http://www.nullterminator.net/java/sub4k/
Last edited by degibson; 11-05-2012 at 08:05 PM.
|
|
|
11-10-2012, 06:18 PM
|
#12
|
|
Moderator Programming
Join Date: Sep 2005
Posts: 8,151
|
Quote:
Originally Posted by degibson
Don't let the naive dissuade you, OP:
- There's a huge value in understanding the machine at the level of base and stack pointers;
- Similarly large value in understanding how high-level languages map to assembly-level constructs;
- Not all platforms afford the luxury of high-level execution environments;
- Programmers write compilers, don't they?
|
Major-league agree with this.
|
|
|
11-11-2012, 08:06 AM
|
#13
|
|
Diamond Member
Join Date: Sep 2000
Location: A nomadic herd of wild fainting goats
Posts: 9,533
|
Quote:
Originally Posted by exdeath
WHAT? You mean I can't have Java on a system with 2k of RAM?! What do you mean I need 2 GB RAM just to write "Hello World!" ?
|
Come now, Java isn't THAT bad. I mean, you should have a system with at least 64mb of memory before trying to do anything with it... but it isn't THAT bad. (Though, come to think of it, our current java solution will eat up around 8gb of ram with everything running and doing nothing... Yeah, not great, but at least I can delude myself into believing that it is a huge system).
__________________
CogBlog - Random Babblings of Cogman mainly focused on software.
|
|
|
11-11-2012, 08:40 PM
|
#14
|
|
Diamond Member
Join Date: Jul 2006
Location: Midwest USA
Posts: 5,700
|
I wouldn't want to read assembly code of i386 CPUs, compile it with gcc for PowerPC, which has much simpler instruction set.
__________________
i7-3770, Intel DZ77SL-50K, VisionTek HD 7850, Dell 2707WFP, X25-M, X-Fi * PC Gamer Since 1991 *
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 12:21 PM.
|