Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Forums > Electronic Projects Design/Ideas/Reviews


Electronic Projects Design/Ideas/Reviews Are you building an electronic project or want to? Maybe you need some assistance? Come and submit your electronic questions here and let our experienced members find a solution.

Reply
 
LinkBack Thread Tools Display Modes
Old 23rd August 2005, 03:43 PM   (permalink)
Default parallel port

here's a little question on parallel port. Many programmers when they want to make bit 2 of control '1' i.e pin 16 write:

outporb(CONTROL, 0X04^0X0b); for example. Why don't they simply write: outportb(CONTROL, 0X0f)? aren't they the same thing?

Let me just explain: 0X04 ^(EXOR) 0x0b is the same thing as (0100 EXOR 1011) which would give us 1111. Now the hardware inverts this to 0100.

If we simply put outportb(CONTROL, 0X0f) it'll mean we're inputting 1111 to CONTROL port and by hardware inversion we have: 0100. Why the obsession with making life difficult? :?
__________________
Everybody can but not everybody will.
aibelectronics is offline  
Old 23rd August 2005, 04:02 PM   (permalink)
Default

It's just for clarity purposes, but may not be recommended simply because an extra step of computation is required.
Asserting the zeroth bit is simply
0x01 ^ 0x0b
Asserting the first bit is simply
0x02 ^ 0x0b
Asserting the second bit is simply
0x04 ^ 0x0b
Asserting the third bit is simply
0x08 ^ 0x0b
checkmate is offline  
Old 23rd August 2005, 04:02 PM   (permalink)
Default

Probably so the programmer can see at a glance wich bit gets modified?

with the 0x04 in the code you can tell bit2 is beeing modified immediately...
Exo is offline  
Old 23rd August 2005, 04:04 PM   (permalink)
Default

Quote:
Originally Posted by checkmate
It's just for clarity purposes, but may not be recommended simply because an extra step of computation is required.
Any decent compiler will optimize it out anyway...
Exo is offline  
Old 23rd August 2005, 04:06 PM   (permalink)
Default parallel port

ahhh! that could be a reason. I guess many people would find my one-step approach easier!
__________________
Everybody can but not everybody will.
aibelectronics is offline  
Reply

Bookmarks

Thread Tools
Display Modes





All times are GMT. The time now is 07:21 PM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker