Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Status
Not open for further replies.

imtisal

Junior Member level 1
Helllo all,

Kindly anyone tell me how to load ADRESH and ADRESL values into one register i.e. 16 bit register. I am using ADFM = 1 [Left Justified Format]
I am using MickroC.
I got some command while searching over internet as follow: -

where value is a 16 bit integer. But I am confused in ADRESH<<8 , whatever the result is in ADRESH, it should become zero after shifting 8 times. Isn't it?
kindly help me to understand this basic idea.

Imtisal

T3STY

Full Member level 4
Shifting a value may temporary extend the value length (may not reduce it though) but the final real value is dictated by the variable used to store the value. A 16 bit value will get truncated into a 8 bit variable while a 8 bit value into a 16 bit variable will have leading zeros extending the value length up to 16.
This being said (I hope you got it), what you found on the web is correct. What the code does is making a OR between two variables where one of them is shifted by 8 bits to the left. As the "value" variable is 16 bit long the operation has to be considered under this maximum length, which gives the next result:
Code:
ADRESL      +   [00][00][00][00][00][00][00][00][09][10][11][12][13][14][15][16] + (zeros at the beginning are the result of value length extension up to 16 bits)
ADRESH << 8     [01][02][03][04][05][06][07][08][00][00][00][00][00][00][00][00]   (zeros at the end are the result of left shifting by 8 bits)
-------------  -----------------
value           [01][02][03][04][05][06][07][08][09][10][11][12][13][14][15][16]
Now in value you stored the ADRESL value at the lower 8 bits and the ADRESH value at the higher 8 bits.

Last edited:
imtisal

imtisal

points: 2

Tahmid

Helllo all,

Kindly anyone tell me how to load ADRESH and ADRESL values into one register i.e. 16 bit register. I am using ADFM = 1 [Left Justified Format]
I am using MickroC.
I got some command while searching over internet as follow: -

where value is a 16 bit integer. But I am confused in ADRESH<<8 , whatever the result is in ADRESH, it should become zero after shifting 8 times. Isn't it?
kindly help me to understand this basic idea.

Imtisal
Make sure value is a 16-bit variable. In that case, the value obtained from ADRESH will not be zero but will be shifted to the upper byte (bits 8-15) of "value". If value is an 8-bit register, then, yes, <<8 will make it zero.

Hope this helps.
Tahmid.

imtisal

imtisal

points: 2

imtisal

Junior Member level 1
Totally got it,
Thanks T3STY and Tahmid.

Once again thanks for such a nice favor.

Stay Blessed.

Imtisal

Status
Not open for further replies.