Page 1 of 2

what is mean't by 1<<0 , 1<<1 in assembly

Posted: Sun Jun 05, 2011 6:50 am
by naf456
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.

Re: what is mean't by 1<<0 , 1<<1 in assembly

Posted: Sun Jun 05, 2011 7:19 am
by Chandra
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.
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:
000000011<<4=00110000
I'm sure it has nothing to do with NASM though because NASM already has 'shl' and 'shr' instructions.

Re: what is mean't by 1<<0 , 1<<1 in assembly

Posted: Sun Jun 05, 2011 7:28 am
by naf456
so ,how come the example used 1<<0 ? surely you can just put 1?

Re: what is mean't by 1<<0 , 1<<1 in assembly

Posted: Mon Jun 06, 2011 12:02 am
by Solar
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:

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
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. 8)

Re: what is mean't by 1<<0 , 1<<1 in assembly

Posted: Mon Jun 06, 2011 1:27 am
by Solar
berkus wrote:You could also go about it in a more friendly manner with a macro (C pseudocode)...
...and getting me annoyed for having to look up the implementation of BIT() to be sure about what you're doing.

See?

You cannot please everyone. 8)

Re: what is mean't by 1<<0 , 1<<1 in assembly

Posted: Mon Jun 06, 2011 1:31 am
by bitshifter
I prefer this method...

Code: Select all

#define BIT0 (1 << 0)
#define BIT1 (1 << 1)
...
It takes a bit more defines but you know what it does without looking it up.

Re: what is mean't by 1<<0 , 1<<1 in assembly

Posted: Mon Jun 06, 2011 1:45 am
by Solar
bitshifter wrote:...but you know what it does without looking it up.
No you don't.

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.

Re: what is mean't by 1<<0 , 1<<1 in assembly

Posted: Mon Jun 06, 2011 2:18 am
by Solar
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()...

Re: what is mean't by 1<<0 , 1<<1 in assembly

Posted: Wed Jun 08, 2011 6:11 am
by Love4Boobies
bitshifter wrote:I prefer this method...

Code: Select all

#define BIT0 (1 << 0)
#define BIT1 (1 << 1)
...
It takes a bit more defines but you know what it does without looking it up.
Are you aware that macros can take arguments? Either way, it doesn't save you much typing so I advise against it as well.

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).

Re: what is mean't by 1<<0 , 1<<1 in assembly

Posted: Thu Jun 09, 2011 7:44 am
by naf456
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. :shock: (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! 8) 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. :P

Re: what is mean't by 1<<0 , 1<<1 in assembly

Posted: Thu Jun 09, 2011 8:00 am
by Solar
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! 8) LOL)
Yes, please do.

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.

Re: what is mean't by 1<<0 , 1<<1 in assembly

Posted: Thu Jun 09, 2011 8:05 am
by naf456
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

Re: what is mean't by 1<<0 , 1<<1 in assembly

Posted: Thu Jun 09, 2011 8:59 am
by naf456
(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.

Re: what is mean't by 1<<0 , 1<<1 in assembly

Posted: Thu Jun 09, 2011 9:45 am
by Chandra
naf456 wrote:And if it makes you feel better by saying I'm foolish in every respect, like everyone else, then so be it
Who else is foolish here?
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.
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:But Unlike you, I have a VIVID, FIERY ROARING PASSION to learn every single aspect and out most detail of these amazing machines.
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:I hope this post shows how I truly feel about this subject
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.

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.

Re: what is mean't by 1<<0 , 1<<1 in assembly

Posted: Thu Jun 09, 2011 10:45 am
by terry
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.
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.

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.