Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/24/01 08:52
Read: times


 
#14414 - RE: Integer to Low and High byte - Oleg
An old English saying goes, "What's the point in having a dog & barking yourself!"
In other words, why manually split your integers when you've got a compiler to do it for you!

Note that many (most? all?) compilers will evaluate constant expressions at compile time; they don't put in all the code to do the calculation every time at runtime!

eg, here is the source & resulting assembler produced by Keil C51:
#define AAFF 0xaaff    
unsigned char aa;      
unsigned char ff;      
                       
aa = AAFF >> 8;        
R     MOV     aa,#0AAH 
ff = AAFF;             
R     MOV     ff,#0FFH 

Note that, in general, it's safer to include a Mask, to ensure that you don't get any unexpected effects from sign-extension, etc; eg,
aa = (AAFF & 0xff00) >> 8;
R     MOV     aa,#0AAH    
ff =  AAFF & 0x00ff;      
R     MOV     ff,#0FFH    
Note that the generated assembler is the same.

List of 12 messages in thread
TopicAuthorDate
Integer into Low and High byte            01/01/70 00:00      
RE: Integer into Low and High byte            01/01/70 00:00      
RE: Integer into Low and High byte            01/01/70 00:00      
RE: Integer into Low and High byte            01/01/70 00:00      
RE: Integer into Low and High byte            01/01/70 00:00      
RE: Integer into Low and High byte            01/01/70 00:00      
RE: Integer into Low and High byte            01/01/70 00:00      
RE: Integer into Low and High byte            01/01/70 00:00      
RE: Integer to Low and High byte - Oleg            01/01/70 00:00      
RE: Integer into Low and High byte - ALL            01/01/70 00:00      
RE: Integer into Low and High byte            01/01/70 00:00      
RE: Integer into Low and High - Lennart            01/01/70 00:00      

Back to Subject List