assembly code

Danimal1209

Senior member
Nov 9, 2011
355
0
0
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?
 

Train

Lifer
Jun 22, 2000
13,863
68
91
www.bing.com
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.
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
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.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,284
3,905
75
Try compiling your C code with gcc -S. That outputs the assembly code equivalent.
 

Kromis

Diamond Member
Mar 2, 2006
5,214
1
81
*Shudder* Assembly...that stuff gave me nightmares, yo! I never learned C either, it was just killing me.
 

lambchops511

Senior member
Apr 12, 2005
659
0
0
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.
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
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?
 

ObscureCaucasian

Diamond Member
Jul 23, 2006
3,934
0
0
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.
 

exdeath

Lifer
Jan 29, 2004
13,679
10
81
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:

exdeath

Lifer
Jan 29, 2004
13,679
10
81
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!" ?
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
13
81
www.markbetz.net
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.
 

Cogman

Lifer
Sep 19, 2000
10,278
126
106
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).
 

postmortemIA

Diamond Member
Jul 11, 2006
7,721
40
91
I wouldn't want to read assembly code of i386 CPUs, compile it with gcc for PowerPC, which has much simpler instruction set.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |