Page 1 of 1
When should I finally read up on Assembly?
Posted: Sun Apr 05, 2015 12:26 am
by mac
At which point in my journey to learn different programing languages should I begin reading into ASM programing, most likely for the x86 processor. I'm already a newb to C (just learning some tutorials today, sometimes tricky but nothing too overwhelming):
Code: Select all
#include <stdio.h>
int main()
{
printf ("Hello, <true name censored>!\n");
getchar ();
}
Damn smartphones, making it more difficult to type stuff. And yes, I know about the return 0 function, I didn't bother because if we're not giving a function any arguments, it's redundant.
Anyway, I feel more confident that I am on my way. I eventually settled on C because of the breadth of fundamental knowledge it brings to me as a relative newb.
Re: When should I finally read up on Assembly?
Posted: Sun Apr 05, 2015 1:36 am
by iansjack
And yes, I know about the return 0 function, I didn't bother because if we're not giving a function any arguments, it's redundant.
Whether a function returns a value has nothing to do with any arguments given to it. And whilst it is not mandatory to return a value from main(), even though it is declared as returning an int, I would say it is good practice to do so just as you would with any other function.
If you can't be bothered to type "return 0" you are not going to find computer programming to your liking.
Re: When should I finally read up on Assembly?
Posted: Sun Apr 05, 2015 1:47 am
by mac
Thanks for that little tip though. I don't mind having to type "return 0" but I am still ways away from success, mind you.
Re: When should I finally read up on Assembly?
Posted: Sun Apr 05, 2015 2:12 am
by alexfru
SeanMc wrote:
Code: Select all
int main()
{
printf ("Hello, <true name censored>!\n");
getchar ();
}
And yes, I know about the return 0 function, I didn't bother because if we're not giving a function any arguments, it's redundant.
main() must return a value if your C compiler operates per the C standard from 1989 (AKA ANSI C). The language standard from 1999 lifts this requirement and main() that executes until its end without return is equivalent to returning 0.
Further, the C standard states that unless other forms of definitions of main() are supported by the compiler, main() must come in one of two forms:
or
I'm not saying this to confuse you or deliberately make your life harder because I'm in some evil mood. I'm saying this because most tutorials (and even some books purporting to be teaching C) are written without taking the language standard seriously and teach bad things or explain things incorrectly or give the reader an impression that C is a lax language and you can bend it any way you wish. Why is it important you might wonder if your program appears to work as you expect?
Well, the reason is that the language by its design (and as reflected in its standard) comes with a number of things that aren't defined or are left to be decided and defined by the compiler writer in different ways. If your C code has things whose behavior isn't defined neither by the standard nor by your compiler documentation, your code may still compile here and now and it may even work here and now, but should you switch to a different version of the compiler or to a completely different compiler or change its optimization options or move the code to a different architecture (ARM or MIPS or PPC or whatever else is out there besides x86), you will run the risk of your code ceasing to work. There have been many cases. Some are nasty as the broken code opens up security holes. Some people who don't get the language and don't care about how its defined and pretend to know better file stupid bugs against gcc and other compilers, demand them fixed and get nothing other than annoying others with their ignorance and arrogance and wasting everyone's time.
IOW, just because your C (or C++) program works here and now, it doesn't necessarily mean it's correct in the face of the language. C (and C++) isn't a particularly friendly language and its compilers won't tell you of all language-specific bugs in your code, even if you ask the compiler to generate all possible warnings (which are signs of bugs, but some are just annoying overly patronizing false alarms, unfortunately). This means that you should actually learn to write proper code, that is, avoid doing bad things that the language standard tells not to do.
Get yourself K&R 2nd edition. It won't teach you bad things if you read it with attention.
Re: When should I finally read up on Assembly?
Posted: Sun Apr 05, 2015 3:08 am
by mac
Thanks for the advice, I didn't see that coming, but I might decide to complete the tutorial I began with first. On the other hand, I guess this too is a bad idea.
Re: When should I finally read up on Assembly?
Posted: Sun Apr 05, 2015 2:16 pm
by cmdrcoriander
SeanMc wrote:Thanks for the advice, I didn't see that coming, but I might decide to complete the tutorial I began with first. On the other hand, I guess this too is a bad idea.
I wouldn't say it's a bad idea
You just do need to be very careful about things that seem kind of pedantic like that in C and C++. That being said, it's definitely a good idea to pick up a few good, well-respected books on the subject - Internet tutorials tend to teach you things fairly incompletely when it comes to C (as you just learned...
)
Re: When should I finally read up on Assembly?
Posted: Sun Apr 05, 2015 11:41 pm
by mac
Is a K&R C 2nd Edition PDF copy from an educational institution considered legit?
Re: When should I finally read up on Assembly?
Posted: Mon Apr 06, 2015 2:51 pm
by cmdrcoriander
SeanMc wrote:Is a K&R C 2nd Edition PDF copy from an educational institution considered legit?
As long as it's actually written by Kernighan and Ritchie you should be fine
Re: When should I finally read up on Assembly?
Posted: Tue Apr 07, 2015 11:17 pm
by mac
I know that each section has a couple of code exercises at the end. Are they to be treated like this, i.e. is the concept to concentrate and practice the exercise every day before it gets easy and then you progress?
How much reading and practicing am I allowed to do in a day so I don't burn myself out? My schedule these days aren't very busy.
Re: When should I finally read up on Assembly?
Posted: Tue Apr 07, 2015 11:27 pm
by alexfru
SeanMc wrote:How much reading and practicing am I allowed to do in a day so I don't burn myself out?
Can you detect when your attention starts wandering or you start skipping over parts of the text and it stops making sense?
Re: When should I finally read up on Assembly?
Posted: Tue Apr 07, 2015 11:56 pm
by mac
Heh maybe. I think that happened to me before.
I am now wondering about exercise 1-4 in the book, converting Celsius temperature to Fahrenheit table. I hope nobody frowns that I had to "cheat" a little (Google) to figure out the solution.
I might post a sample code of my solution later.