OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 4:04 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: When should I finally read up on Assembly?
PostPosted: Sun Apr 05, 2015 12:26 am 
Offline
Member
Member

Joined: Tue Sep 23, 2014 6:12 pm
Posts: 144
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:
#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.


Top
 Profile  
 
 Post subject: Re: When should I finally read up on Assembly?
PostPosted: Sun Apr 05, 2015 1:36 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
Quote:
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.


Top
 Profile  
 
 Post subject: Re: When should I finally read up on Assembly?
PostPosted: Sun Apr 05, 2015 1:47 am 
Offline
Member
Member

Joined: Tue Sep 23, 2014 6:12 pm
Posts: 144
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.


Top
 Profile  
 
 Post subject: Re: When should I finally read up on Assembly?
PostPosted: Sun Apr 05, 2015 2:12 am 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 1108
SeanMc wrote:
Code:
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:
Code:
int main(void)

or
Code:
int main(int argc, char** argv)


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.


Top
 Profile  
 
 Post subject: Re: When should I finally read up on Assembly?
PostPosted: Sun Apr 05, 2015 3:08 am 
Offline
Member
Member

Joined: Tue Sep 23, 2014 6:12 pm
Posts: 144
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.


Top
 Profile  
 
 Post subject: Re: When should I finally read up on Assembly?
PostPosted: Sun Apr 05, 2015 2:16 pm 
Offline
Member
Member

Joined: Tue Jan 20, 2015 8:33 pm
Posts: 29
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... :P)


Top
 Profile  
 
 Post subject: Re: When should I finally read up on Assembly?
PostPosted: Sun Apr 05, 2015 11:41 pm 
Offline
Member
Member

Joined: Tue Sep 23, 2014 6:12 pm
Posts: 144
Is a K&R C 2nd Edition PDF copy from an educational institution considered legit?


Top
 Profile  
 
 Post subject: Re: When should I finally read up on Assembly?
PostPosted: Mon Apr 06, 2015 2:51 pm 
Offline
Member
Member

Joined: Tue Jan 20, 2015 8:33 pm
Posts: 29
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 :)


Top
 Profile  
 
 Post subject: Re: When should I finally read up on Assembly?
PostPosted: Tue Apr 07, 2015 11:17 pm 
Offline
Member
Member

Joined: Tue Sep 23, 2014 6:12 pm
Posts: 144
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. :)


Top
 Profile  
 
 Post subject: Re: When should I finally read up on Assembly?
PostPosted: Tue Apr 07, 2015 11:27 pm 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 1108
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?


Top
 Profile  
 
 Post subject: Re: When should I finally read up on Assembly?
PostPosted: Tue Apr 07, 2015 11:56 pm 
Offline
Member
Member

Joined: Tue Sep 23, 2014 6:12 pm
Posts: 144
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 39 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group