Division routine for ATTINY85

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi. I need some help with 16/16 division routines. Does anyone know a routine in C language for ATINY85?

 

This topic has a solution.

Newbie!

Last Edited: Mon. Mar 12, 2018 - 05:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tiny85 is not one of the brain-dead ones. So, how will division be different than on a regular AVR?

 

What do you expect from your 16/16 division? Do you expect just the integer part? (there is a standard C operation for that, called integer division). Or do you expect some sort of mix of integer part and fractional part? If the latter, then look at the reference Joey provided.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Fri. Mar 9, 2018 - 07:45 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

pabloleiva1969@hotmail.com wrote:
16/16 division routines. Does anyone know a routine in C language for ATINY85?

??? and LOL -- surely your C compiler will have an implementation for the / operator.  No need to write a routine, is there?

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1
 int16_t num1 = 128;
 int16_t num2 = 16;
 int16_t result;
 
 .......
 
  result = num1 / num2;
  
  ......
  
  

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Google must have been broken when you did your search..?

 

http://www.avr-asm-tutorial.net/avr_en/calc/index.html

 

 

Greg Muth

Portland, OR, US

Xplained/Pro/Mini Boards mostly

 

Make Xmega Great Again!

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But your tutorial title says "ASM" and OP said "C".

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Welcome pabloleiva1969 -

 

My apologies for not welcoming you earlier.

 

I really can understand that someone who has not used C very much might not even be aware of the integer-divide operation. Or, the modulus operator. Or any number of "odd" logical operators, like XOR.

 

Lets cut the OP a little slack. And we probably ought to provide some slack in The OP's not knowing that the Tiny85 is not very different, in most respects, from the "full size" Mega chips. That is not that obvious from the spec sheet unless you already know about one or more Mega devices.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Sat. Mar 10, 2018 - 12:59 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
I really can understand that someone who has not used C very much might not even be aware of the integer-divide operation.

C'mon.  Even a beginning student of a language will have looked at the table of operators.  And even a beginner would, I would think, recognize/look for +-*/.

 

The flippant responses are, to some extent, intended for OP to clarify further.  There have been some threads on "if the AVR is 8 bit, how do I do operations (in C or whatever) on wider items?"  Or perhaps indeed OP's instructor has given the task of writing a division routine in C to illustrate/exercise some programming feature such as looping (for the repeated subtraction) or even recursion.  We don't know.

 

ka7ehk wrote:
The OP's not knowing that the Tiny85 is not very different,

Other than the mention that the '85 is the target AVR model, I didn't read that much into the mention.  Certainly not as much as you did.

 

Again, clarification needed on the intent.  If any serious work, then the instruction set document would be used.  But that is only (usually) indirectly pertinent to C programming.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@theusch wrote:

But your tutorial title says "ASM" and OP said "C".

True, but as already pointed by you, the OP's question is ridiculous in the context of C programming.

Greg Muth

Portland, OR, US

Xplained/Pro/Mini Boards mostly

 

Make Xmega Great Again!

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm so sorry. I had a confussion with the div() function. Thank you all.

Newbie!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 But even div() (and ldiv()) from <stdlib.h> are a fairly unusual way to do division in a C compiler? Normally you just use the '/' operator that was shown in #5. The only time to use div() is when you need BOTH the dividend and the remainder at the same time.