Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 19:56 28 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Anyone know Assembler language?

     Page 3 of 3    
Author Message
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3805
Posted: 03:48pm 22 May 2023
Copy link to clipboard 
Print this post

  lew247 said  What I DONT get is
do you read the binary number from the LEFT or the RIGHT
n0 is first digit on the LEFT, or first digit on the RIGHT?

There is not really a standard, just as there isn't for the order of (let's call them bytes) with a (let's say word) :(

On a good day the data sheet makes it clear. The rest of the time you guess. When guessing I start with LE (little endian) for bytes (when relevant) and lowest order bit in data sheet to be bit 0 in a byte/word.

Sometimes a data sheet gives a program snippet or a web search finds working examples so you can avoid guessing.

Short of finding a software example, I suspect phil99 will be right in this case.

John
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 03:55pm 22 May 2023
Copy link to clipboard 
Print this post

  phil99 said  
Second byte = 6148 And 255

> ? bin$(6148>>8,8)
00011000
> ? bin$(6148 And 255,8)
00000100
>

Phil
Where did you get the 8 and 255 from?
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 04:03pm 22 May 2023
Copy link to clipboard 
Print this post

  JohnS said  
Short of finding a software example, I suspect phil99 will be right in this case.
John

0x60 ; Prescaler second byte
0x34 ; Prescaler first byte
 
IanRogers

Senior Member

Joined: 09/12/2022
Location: United Kingdom
Posts: 151
Posted: 04:52pm 22 May 2023
Copy link to clipboard 
Print this post

  lew247 said  
  phil99 said  
Second byte = 6148 And 255

> ? bin$(6148>>8,8)
00011000
> ? bin$(6148 And 255,8)
00000100
>

Phil
Where did you get the 8 and 255 from?


He is shifting the 16 bit number into two bytes..

6148 = b' 0001 1000 0000 0100

>> 8 will lose the bottom 8 digits
AND 255 will lose the top 8 digits splitting them into High byte and Low byte
I'd give my left arm to be ambidextrous
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3805
Posted: 04:59pm 22 May 2023
Copy link to clipboard 
Print this post

AND 255 may be easier to grasp if you think of it as AND &hFF

A byte of all 1s is FF; the AND keeps those bits which are 1.

John
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2140
Posted: 01:26am 23 May 2023
Copy link to clipboard 
Print this post

  Quote  Where did you get the 8 and 255 from?
Apologies for not clarifying.
As explained above >>8 moves the top 8 bits down to make the high byte and the bottom 8 bits drop off the edge (... of the World. Past the Elephants it's Turtles all the way down).
255 is my lazy way of writing &B11111111.

An alternative method to split the bytes.

HighByte = 6148 \ 256  '256 = 2^8, integer division discards the remainder (anything below 1)
LowByte = 6148 Mod 256  'Modulo division discards the result and restores the remainder - the low 8 bits in this case.

These however, use more clock cycles than Shift and AND.
? bin$(6148 \ 256, 8)
00011000
> ? bin$(6148 mod 256, 8)
00000100
>

Edit.
Tried timing it 100,000 times and the difference is insignificant.
> timer=0:for m=0 to 100000:p=6148\256:n=6148 mod 256:next:? timer
6542.66
> timer=0:for m=0 to 100000:p=6148>>8:n=6148 and 255:next:? timer
 6276.764
>

Edited 2023-05-23 13:48 by phil99
 
     Page 3 of 3    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024