what is mean't by 1<<0 , 1<<1 in assembly
what is mean't by 1<<0 , 1<<1 in assembly
the question is pretty much in the title.
on the bare bones example on the boot strap it shows the bitwise shift operator, but I don't get what is meant by the right value? I've scanned the nasm document and can't see anything related and every boot strap example i've seen just use a binary number. it would be nice for a clean answer.
on the bare bones example on the boot strap it shows the bitwise shift operator, but I don't get what is meant by the right value? I've scanned the nasm document and can't see anything related and every boot strap example i've seen just use a binary number. it would be nice for a clean answer.
I don't suffer from insanity. I enjoy every minute of it.
Re: what is mean't by 1<<0 , 1<<1 in assembly
The right value is ' the number of bits to shift'. For example, 3<<4 stands for 'the bits of the integer 3 be shifted 4 places left'. The binary representation of this would be:naf456 wrote:the question is pretty much in the title.
on the bare bones example on the boot strap it shows the bitwise shift operator, but I don't get what is meant by the right value? I've scanned the nasm document and can't see anything related and every boot strap example i've seen just use a binary number. it would be nice for a clean answer.
000000011<<4=00110000
I'm sure it has nothing to do with NASM though because NASM already has 'shl' and 'shr' instructions.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
Re: what is mean't by 1<<0 , 1<<1 in assembly
so ,how come the example used 1<<0 ? surely you can just put 1?
I don't suffer from insanity. I enjoy every minute of it.
Re: what is mean't by 1<<0 , 1<<1 in assembly
berkus?
Relax.
@naf456:
This kind of code is frequently seen when handling "flag" values, i.e. when every bit in an integer stands for something specific. Compare:
It's about explicitness. 1 << 0 vs. 1 makes it clear that you are setting bit #0 instead of the numerical value 1.
And berkus got testy because this really is rather basic programming knowledge.
Relax.
@naf456:
This kind of code is frequently seen when handling "flag" values, i.e. when every bit in an integer stands for something specific. Compare:
Code: Select all
int flag_1 = 1 << 13; // setting bit #13
int flag_2 = 8192; // setting bit #13
int flag_3 = 1 << 13 | 1 << 1 // setting bits #13 and #1
int flag_4 = 8194; // setting bits #13 and #1
And berkus got testy because this really is rather basic programming knowledge.
Every good solution is obvious once you've found it.
Re: what is mean't by 1<<0 , 1<<1 in assembly
...and getting me annoyed for having to look up the implementation of BIT() to be sure about what you're doing.berkus wrote:You could also go about it in a more friendly manner with a macro (C pseudocode)...
See?
You cannot please everyone.
Every good solution is obvious once you've found it.
-
- Member
- Posts: 50
- Joined: Sun Sep 20, 2009 4:03 pm
Re: what is mean't by 1<<0 , 1<<1 in assembly
I prefer this method...
It takes a bit more defines but you know what it does without looking it up.
Code: Select all
#define BIT0 (1 << 0)
#define BIT1 (1 << 1)
...
Re: what is mean't by 1<<0 , 1<<1 in assembly
No you don't.bitshifter wrote:...but you know what it does without looking it up.
You won't believe the kind of **** I've seen being done in harmless-looking macros / constants.
My hint for the debugger / maintainer: NEVER trust that a macro actually does (only) what the name implies. Always look it up.
My hint for the programmer: Unless it gives you real functional benefit or really saves lots of typing, don't use custom macros (or typedefs).
Oh, and while we're at it: Use const int for constants, not the preprocessor. Also saves the debugger / maintainer some headache.
Every good solution is obvious once you've found it.
Re: what is mean't by 1<<0 , 1<<1 in assembly
Of course stuff like PAGE_SIZE is acceptable. But far too often you get stuff like PRINT(), or - seen just recently, and I'm not kidding - MD5()...
Every good solution is obvious once you've found it.
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: what is mean't by 1<<0 , 1<<1 in assembly
Are you aware that macros can take arguments? Either way, it doesn't save you much typing so I advise against it as well.bitshifter wrote:I prefer this method...It takes a bit more defines but you know what it does without looking it up.Code: Select all
#define BIT0 (1 << 0) #define BIT1 (1 << 1) ...
As for macros in general, they aren't as useful as they used to be (because of the const and inline keywords). There are very few reasons for which they should be used (i.e., consistency with old code, backwards compatibility with some older compiler, or a very specific task---hard to think of one atm).
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
Re: what is mean't by 1<<0 , 1<<1 in assembly
Thanks for the reply.
I am in the progress of reading the 1800 page whooper from intel. -it's boring... REALLY boring... I just want to write some code. (and unfortunatly the manuals go over more of the theory side, not the actual assembly coding side)
I'll think I'll just go off to the Windows Phone 7 development side now (That way I can earn REAL money! LOL)
EDIT : I know berkus : http://wiki.osdev.org/Beginner_Mistakes
a paragraph down "What this is NOT" -
"Do not expect this Wiki, or the forum, to be some kind of complete guide to my own OS, let alone a guide to programming skills in general."
Just sometimes, you can't be asked to search hours on end through google.
I am in the progress of reading the 1800 page whooper from intel. -it's boring... REALLY boring... I just want to write some code. (and unfortunatly the manuals go over more of the theory side, not the actual assembly coding side)
I'll think I'll just go off to the Windows Phone 7 development side now (That way I can earn REAL money! LOL)
EDIT : I know berkus : http://wiki.osdev.org/Beginner_Mistakes
a paragraph down "What this is NOT" -
"Do not expect this Wiki, or the forum, to be some kind of complete guide to my own OS, let alone a guide to programming skills in general."
Just sometimes, you can't be asked to search hours on end through google.
Last edited by naf456 on Thu Jun 09, 2011 8:01 am, edited 1 time in total.
I don't suffer from insanity. I enjoy every minute of it.
Re: what is mean't by 1<<0 , 1<<1 in assembly
Yes, please do.naf456 wrote:boring... I just want to write some code. [...] I'll think I'll just go off to the Windows Phone 7 development side now (That way I can earn REAL money! LOL)
There's two kinds of programmers.
Those who "just want to write some code", and those who realize that reading technical documentation is part of the job profile.
Every good solution is obvious once you've found it.
Re: what is mean't by 1<<0 , 1<<1 in assembly
where did you get that from?
All you install Visual studio 2010 with the XNA framework 4.0 and Windows phone 7 API's
Only thing is the £60 Developer Licence
The market is small (ish) Games do get alot of attention. especially with Xbox live support.
EDIT 1 : Why b sarcastic about it? Yes I'll have to read up the documentation about the api's, but atleast I don't have to read several manuals 1000's of pages each. The only thing I HATE about it, is that I will be like everyone else- A common high-level developer
EDIT 2 : I've finally came to my senses
All you install Visual studio 2010 with the XNA framework 4.0 and Windows phone 7 API's
Only thing is the £60 Developer Licence
The market is small (ish) Games do get alot of attention. especially with Xbox live support.
EDIT 1 : Why b sarcastic about it? Yes I'll have to read up the documentation about the api's, but atleast I don't have to read several manuals 1000's of pages each. The only thing I HATE about it, is that I will be like everyone else- A common high-level developer
EDIT 2 : I've finally came to my senses
Last edited by naf456 on Thu Jun 09, 2011 9:09 am, edited 3 times in total.
I don't suffer from insanity. I enjoy every minute of it.
Re: what is mean't by 1<<0 , 1<<1 in assembly
(I feel like I'm making enemies here.)
Yes I understand that Reading documentation and studying source code is a big deal to make me educated about my tool set I'm using.
I've been studying OS Development for the past 18 months, all I got stuck on is one (albeit simple) problem which I didn't understand in the source code.
I have terrible grades because of all this - I should have listened to my friends when it comes down to revising. Yes I'm an idiot- And Fancy Broadcasting it to this Sh***y world!!
And if it makes you feel better by saying I'm foolish in every respect, like everyone else, then so be it.
I WILL master OS Development - As it is my GOAL and PASSION to study it.
I can't think of anything in this world I would possibly do right now, apart from this.
I Have been pulling apart and repairing these amazing pieces of machine before I can even remember.
It may sound crazy, but I actually am in love with these dam things- there the only things that make me happy within myself- and there the only things I plead to understand-
Yes, I do not have the equal amount of acquired information like you guys have- But information can be that- Acquired.
But Unlike you, I have a VIVID, FIERY ROARING PASSION to learn every single aspect and out most detail of these amazing machines.
So, please,If you with me, and want to help, thank you. it's greatly appreciated. if all you want to do is push everyone over that has a small tumble, then please, p*** off- no one needs a person like that
I hope this post shows how I truly feel about this subject - I have sacrificed my social life and my grade's to get where I am and I would d the same again.
Yes I understand that Reading documentation and studying source code is a big deal to make me educated about my tool set I'm using.
I've been studying OS Development for the past 18 months, all I got stuck on is one (albeit simple) problem which I didn't understand in the source code.
I have terrible grades because of all this - I should have listened to my friends when it comes down to revising. Yes I'm an idiot- And Fancy Broadcasting it to this Sh***y world!!
And if it makes you feel better by saying I'm foolish in every respect, like everyone else, then so be it.
I WILL master OS Development - As it is my GOAL and PASSION to study it.
I can't think of anything in this world I would possibly do right now, apart from this.
I Have been pulling apart and repairing these amazing pieces of machine before I can even remember.
It may sound crazy, but I actually am in love with these dam things- there the only things that make me happy within myself- and there the only things I plead to understand-
Yes, I do not have the equal amount of acquired information like you guys have- But information can be that- Acquired.
But Unlike you, I have a VIVID, FIERY ROARING PASSION to learn every single aspect and out most detail of these amazing machines.
So, please,If you with me, and want to help, thank you. it's greatly appreciated. if all you want to do is push everyone over that has a small tumble, then please, p*** off- no one needs a person like that
I hope this post shows how I truly feel about this subject - I have sacrificed my social life and my grade's to get where I am and I would d the same again.
I don't suffer from insanity. I enjoy every minute of it.
Re: what is mean't by 1<<0 , 1<<1 in assembly
Who else is foolish here?naf456 wrote:And if it makes you feel better by saying I'm foolish in every respect, like everyone else, then so be it
You've been studying OS Development for the past 18 months and so are we. In fact, there are some guys over here who are studying OS Development for more than 5 years now. The only difference is that we're commited to what we want to achieve and you're not.naf456 wrote:I've been studying OS Development for the past 18 months, all I got stuck on is one (albeit simple) problem which I didn't understand in the source code.
So you are on your sacred journey to be a human-encyclopedia without ever requiring to refer to books and documents. But you seem to behave differently. A small obstacle in your path changes your ambition and guides you to a different path. You know what? That exactly is the reason why you don't know simple stuffs like 'bit shifting'.naf456 wrote:But Unlike you, I have a VIVID, FIERY ROARING PASSION to learn every single aspect and out most detail of these amazing machines.
It does. In fact, this posts acknowledges us that you're a noble guy who want to write few lines of code and then cast a magic spell on it so that it will start pouring money and pride over you from all around this world. You are a guy who don't need any sort of technical documents because you know everything in this world(and that too without reading). I may be wrong, of course, but that is what your post reflects.naf456 wrote:I hope this post shows how I truly feel about this subject
And yes, don't be offended by it because you are the one who started all these. You got the answers you want, you acted like know-nothing and then later turned offensive to everyone who just showed you a right way.
Cheers.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
Re: what is mean't by 1<<0 , 1<<1 in assembly
I personally don't think it is worth that sacrifice mainly because social life is important for happiness in my opinion (saying this as a married man and father) and I used my good grades to get a job working in the OS group for a medium sized company that maintains several seperate real-time operating systems.naf456 wrote:(I feel like I'm making enemies here.)
I hope this post shows how I truly feel about this subject - I have sacrificed my social life and my grade's to get where I am and I would d the same again.
Yup, that is right.... I'm living the dream..... Have a job where all of the junk on this forum is actually useful.... All thanks to good grades and achieved after getting married.....
And by the way, I also published an app on the iTunes app store that I wrote in my free-time at home. In my opinion good developers are curious about new technology. Don't let anyone make you feel ashamed about that.