Number must be positive and less than 8

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

So i have this piece of code 

inline void sendByte(uint8_t clr) {
	for(uint8_t i = 0; i < 8; i++) {
		if((clr & (1 << (7-i))) > 0) {
			asm volatile(
				"sbi %[port], %[pin] \n\t"
				".rept %[delayH] \n\t"
				"nop \n\t"
				".endr \n\t"
				"cbi %[port], %[pin] \n\t"
				".rept %[delayL] \n\t"
				"nop \n\t"
				".endr \n\t"
				::
				[port]	"I" (_SFR_IO_ADDR(PORT)),
				[pin]	"I" (PIN),
				[delayH]	"I" (T1HC),
				[delayL]	"I" (T1LC)
			);
		} else {
			
		}
	}
}

and when i compile it it gives me this error, any idea how to fix this?

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

1)  Your error list shows a span of over 100 lines -- much more than the posted fragment.

2)  Which line is 51?  Which line is 55?

3)  Aaah, GCC inline assembler.  The infinite-value toolchain.  Those with a good supply of eye of newt might be able to help but not us mere mortals.

 

(if I had to guess, it applies to pin or PIN)

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

aj22r wrote:
asm volatile( "sbi %[port], %[pin] \n\t"  line 51?

".rept %[delayH] \n\t"

"nop \n\t"

".endr \n\t"

"cbi %[port], %[pin] \n\t" line 55?

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

When you look into inline gcc assembly... it looks back at you.

 

I suppose in your program PIN is higher than 7 and then the sbi and cbi instructions go out of range? Or maybe PIN is not a constant?

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

aj22r wrote:
So i have this piece of code

Is that something you wrote yourself, or something you found elsewhere ?

 

	for(uint8_t i = 0; i < 8; i++) {
		if((clr & (1 << (7-i))) > 0) 		

Think about the possible values for i in that loop;

 

For each of those values, think about what 

(1 << (7-i))

becomes ...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I forgot to mention this:
#define PORT PORTB
#define PIN 0x20

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

Is that something you wrote yourself, or something you found elsewhere ?

I found the assembly part elsewhere, but the other stuff i wrote myself

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

It is very hard for us to map the error messages to the source code snippet you posted.

 

Do us all two favors so that we can help you better.

 

FAVOR 1:

i) Do a rebuild (i.e. a clean followed by a build)

ii) Switch to the Output tab (where the complete build output is shown)

iii) Select everything

iv) Copy

v) Paste into post you make here

 

FAVOR 2:

Post complete source so that we can see all #define's etc. If they are in a separate header file then post that too.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

go on - what about the loop values, then.

 

Use pencil & paper if necessary...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
				"sbi %[port], %[pin] \n\t"
...
				"cbi %[port], %[pin] \n\t"
...
				[pin]	"I" (PIN),
#define PIN 0x20

You have to define PIN as a bit number (5 in this case), not as a mask.

Stefan Ernst

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

awneil wrote:
go on - what about the loop values, then.
I do not see any problem. "i" goes from 0 to 7, so "(7-i)" goes from 7 to 0.

Stefan Ernst

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

Exactly, sbi and cbi assembly instructions take the bit number as argument, and not the bit mask.

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

Is zero positive ... ?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
Is zero positive ... ?
What are you talking about?

Stefan Ernst

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

The message said, "must be positive..."

 

But I agree that it's a red herring - it'll be the "bit position - not mask" issue ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
The message said, "must be positive..."
Oh, the error message. I thought it was also related to the loop values.

Stefan Ernst

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

The message said, "must be positive..."

The error message has an error ;-)

"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."

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

 

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

He who fights with bugs should look to it that he himself does not become a bug.  And...

When you look into inline gcc assembly... it looks back at you.

 

Greg Muth

Portland, OR, US

Xplained/Pro/Mini Boards mostly

 

Make Xmega Great Again!

 

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

The error message has an error ;-)

...but the difference between the positive integers and the non-negative integers is 0.devil

Greg Muth

Portland, OR, US

Xplained/Pro/Mini Boards mostly

 

Make Xmega Great Again!

 

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

awneil wrote:

Is zero positive ... ?

 

 

Well, it's non-negative :P

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

I think this is a rigidly defined area of doubt and uncertainty ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Anyone remember one-eyed no-nosed nothings?

Iluvatar is the better part of Valar.

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

No, but I remember one-eyed one-horned flying purple people eaters.

"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."

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

 

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

What do you try to do?

 

sbi can't take parameters, it's a fixed instruction!

 

To do what you want you have to make it with a AND with a mask and then use brne/breq.

Last Edited: Tue. Dec 5, 2017 - 12:12 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joeymorin wrote:
purple people eater
Which is what my twin brother called the first car he ever owned - a purple mark 2 Cortina:

 

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

Ooh baby! That’s shagadelic!

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

Yep, those seats must have seen plenty of action back in the day ;-)

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

joeymorin wrote:
No, but I remember one-eyed one-horned flying purple people eaters.
I have the movie.

Iluvatar is the better part of Valar.

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

I didn't even know it existed!  I had the '45 of the song.

 

NPH before Doogie and Dr. Horrible... I wonder if it's worth watching...?

"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."

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

 

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

joeymorin wrote:
NPH before Doogie and Dr. Horrible... I wonder if it's worth watching...?

Now you made me do a Google session, and the "Songfacts" are interesting

http://www.songfacts.com/detail....

...which includes

The song got its own Disney Channel film in 1988 with Purple People Eater, in which a young boy plays the song and accidentally summons the creature itself, who then befriends him on an adventure. Neil Patrick Harris plays the boy, who later went on to play Doogie Howser M.D..

...and hits for the "movie" on Wikipedia and IMDB.

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

Then there's C.W. McCall's 'Convoy'... followed by Kris Kristofferson's 'Convoy'  ;-)

 

 

"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."

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

 

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

My Apologies to the OP for the community dragging your thread into the abyss.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

My Apologies to the OP for the community dragging your thread into the abyss.

Yeah, that was me :(

"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."

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