• AVR Freaks

LockedConfusing in the assembly language!!??(Beginer)

Page: < 12 Showing page 2 of 2
Author
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Confusing in the assembly language!!??(Beginer) 2006/03/02 16:14:47 (permalink)
0
I recall being told that the stack was a loose circular buffer by Stan D'Souza, a while back also.
 
It makes no sense to have extra silicon on the stack. I got a bad taste in my mouth ever since I heard that explanation from AH.
Thank you for bringing it to the top of stack. Now I can release a few amygdala synapses and move them to the hypocampus.
 
#21
ric
Super Member
  • Total Posts : 29951
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
RE: Confusing in the assembly language!!??(Beginer) 2006/03/02 19:41:51 (permalink)
0
I suspect that AH was only ever talking about what the simulator does.
It's a pity she abandoned that thread just when it was getting interesting :)

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#22
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Confusing in the assembly language!!??(Beginer) 2006/03/03 04:30:44 (permalink)
0
It is isn't it? But from what I can see, the simulator behaves exactly as the silicon does. You can make MPSIM to break or report on stack faults, but it will behave as a true circular buffer. I wonder if this is true for all PICs. I will include this test suite to all my next projects that use different chips... It will become a quest for the holy grail.
#23
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Confusing in the assembly language!!??(Beginer) 2006/03/03 04:45:31 (permalink)
0
ORIGINAL: ric

I suspect that AH was only ever talking about what the simulator does.

 
I think not. She stated clearly that the silicon was implemented in such a way that the stack would be filled with 0x000 on underflow, and the simulator should do the same thing. I recall having tested it on a 16F688 at the time, but my test then did not include interrupts, so the chip simply stopped cold. But never did it on a 16F877. I took what she said by face value and forgot about it.
 
 
 
 
#24
Olin Lathrop
Super Member
  • Total Posts : 7463
  • Reward points : 0
  • Joined: 2004/02/26 17:59:01
  • Location: Littleton Massachusetts
  • Status: offline
RE: Confusing in the assembly language!!??(Beginer) 2006/03/03 04:45:40 (permalink)
0
I wonder if this is true for all PICs.

It definitely is not.  The PIC 18 stack is not circular.  It has overflow and underflow detection capability explicitly documented in the data sheet.  The dsPICs keep their stack in user RAM.  There is a hardware SPLIM register for detecting stack overflow, but there is no hardware to detect undeflow.  I'm guessing the 12 bit core is just like the 14 bit core with a 1 bit instead of 3 bit stack index.  I'm following Microchip's lead on the PIC 17 and don't remember anything about it.
#25
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Confusing in the assembly language!!??(Beginer) 2006/03/03 04:58:34 (permalink)
0
Of course. I should have said "I wonder if this is true for all 14bit PICs". The 16bit stack is much better, with TOS manipulation capability and stack fault handling capability. It is possible to write stack fault traps for the PIC18 and extend the stack depth, a severe time penalty, but useful sometimes.
 
BTW, it most probably is the exact same circuit description block used for all 14bit cores. There is no logic reason for using a different circuit, because anything different is more complex than a true circular buffer. The only thing that is not clear is whether the stack content is cleared on a power-on RESET or not. If utmost circuit and interconnection savings was the rule, I bet there is no power-on clear for those flipflops.
#26
MartynJ
Super Member
  • Total Posts : 290
  • Reward points : 0
  • Joined: 2004/09/08 04:16:16
  • Location: Swindon England
  • Status: offline
RE: Confusing in the assembly language!!??(Beginer) 2006/03/03 06:03:56 (permalink)
0
ORIGINAL: PIC16F7X7 Data Sheet


The stack operates as a circular buffer. This means that
after the stack has been PUSHed eight times, the ninth
push overwrites the value that was stored from the first
push. The tenth push overwrites the second push (and
so on).
 
Haven't you just proved that the data sheet is in fact correct? There is no reference to a processor reset due to stack underflow, and there would be some strange logic indeed tagged onto the above circular buffer to provide this functionality. The sole reference to stack underflow is in fact...
ORIGINAL: PIC16F7X7 Data Sheet

Note 1: There are no Status bits to indicate stack overflow or stack underflow conditions.


Martyn
#27
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Confusing in the assembly language!!??(Beginer) 2006/03/03 08:31:13 (permalink)
0
We have read the datasheets.

If you followed the links to the other threads, you would share with us the astonishment of being told that the stack is a circular buffer for PUSH, but not for POP. This being the central point of the discussion here, the fact that we all have read in the DSs the stack being defined as a circular buffer.

The whole discussion started when forummember danish.ali reported that on MPSIM v7.20 the stack underflow caused a RESET, and asked for clarifications if this happened in real silicon. I confirmed his findings. Then AH from Microchip told us that the stack in PIC16 devices behaved like a circular buffer for PUSH, but as a LIFO for POP, and that in silicon the stack underflow caused a RESET. AH told us that the datasheets were imprecise and should be changed.

ORIGINAL: AH

[...] it is LIFO, but not circular on POP. In silicon on underflow the PC will be filled with 0x00 that is top of stack. The stack is not implemented to handle circular buffer during POP, because it has already overwritten the previous addresses and on 2 returns it will come back to top of stack instead of reaching bottom of the stack.

I hope this clarifies your doubt about stack.

Regards
AH


After that, I did not test this on the PIC16F877 until now, when I could dismiss that claim.
#28
MartynJ
Super Member
  • Total Posts : 290
  • Reward points : 0
  • Joined: 2004/09/08 04:16:16
  • Location: Swindon England
  • Status: offline
RE: Confusing in the assembly language!!??(Beginer) 2006/03/03 08:58:54 (permalink)
0
I confess I hadn't read danish.ali's thread (until just), and skimmed this one - my confusion being that the datasheet is very clear in its description of stack overflow - an underflow 'counter' would seem a strange addition to what is clearly a circular buffer (it would require to count overflows to underflow correctly? To infinity? etc). Apologies if I added to the frustration!

Martyn
#29
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Confusing in the assembly language!!??(Beginer) 2006/03/06 16:02:28 (permalink)
0
May I know that, after I have the Seebeck coefficient value and I need to display it out, whether I need to do the binary to decimal conversion before the display? Other than that, I could I set the decimal places of the value? Whether I could get an output with decimal places?
#30
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Confusing in the assembly language!!??(Beginer) 2006/03/06 17:49:05 (permalink)
0
To tell you the truth, I still don't know how you will compute the seebeck coefficient, unless you have 2 points of measurement with a calibrated temperature setup. Is that it? You kave a calorimeter or precision calibrated temperature lab setup that will place the thermopile at 2 precise temperature points?
 
I suggest you to take a number of measurements (like 64) for each point and then average all the measurements to get a correction for noise and drift.
 
After you make all the computations, you must convert your results to decimal (BCD), and then to ascii. If you followed my advice and used binary fixed point, this is really easy: take the integer part of the fixed point number and convert it to BCD. Then, if you want to show the number with, say, 3 decimal places, multiply the fraction by 0x03E8 (decimal 1000), and then convert the integer part of this result to BCD.
 
 
#31
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Confusing in the assembly language!!??(Beginer) 2006/03/07 23:28:15 (permalink)
0
Sorry!! I need your help again. I have read a lot of stuff related to fixed point. But the more I read the more question marks inside my brain. There are a lot of questions that I would like to ask. Hope you can answer me. sad
 
You told me that I should use fixed point division and fixed point multiplication. But whether I can get the input in fixed point as well? Whether the A/D conversion will convert the analogue input the fixed point binary number? Or it will always get in interger binary number? Since it will only convert the input to 10 bit binary, then how i load the number into the 16 bit fixed point number?
 
For example 16 bit fixed point number. 0x1674. is it the 16 is integer number and 74 is the number behind the decimal place?
 
for example, if i want to divide 10.8 by 2.2. 10.8 =dividend and 2.2 = divisor. May I know the 10.8 will look like what in 16 bit binary number? And if I would like to load them in hi_dividend and low_dividend, what binary number will load into each of them?
 
 
#32
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Confusing in the assembly language!!??(Beginer) 2006/03/08 05:34:51 (permalink)
0
There is not much to it:
 
1) A binary fixed point number is, for all purposes, an integer number. You simply cannot tell the difference by looking at it, and neither can the math functions. For the math functions, the numbers are just integers. That's the beauty of it: you use the same functions you would for integer math.
 
2) The 'binary point' can be anywhere in the number. It's YOU who decide where it is. When working with small integers, but requiring high precision, it is useful to have 32bit numbers with 24bit fractions. This is called 'Q24' in fixed point jargon.
 
3) To transform a quantity in a binary fixed point number, you simply shift that quantity by the number of binary fractional places. So, to get the quantity '10.8' into Q24 32bit binary fixed point, you shift 10.8 by 24bits: (10.8 * 2^24) = 0x0ACCCCCC. The binary point is at the bit 23, with the top byte being the integer part.
 
4) Addition and subtraction must have the 'Q's aligned, i.e., the binary points should be aligned. If you have different Q formats, like Q24 and Q22, you have to shift one or both until the points are aligned.
 
5) Multiplication does not need to be aligned, and the results fractional part is the sum of the 'Q's. So a Q8 * Q24 produces a Q32. The result bit width is the sum of bits of the 2 factors.
 
6) Division is the same as multiplication Q's don't need to be aligned, but the result Qs are the subtraction of dividend Q and divisor Q. Division has one caveat: integer division will not create the extended fractional bits lower than 1. If you are using integer division, you always need to have the dividend larger than the divisor. This is obtained if you use a 32bits Q24 divided by a 16bits Q8, for example. Then you use a 32/16 integer division routine, and obtain a 32bit result, with Q16 fraction.
For example: (10.8 / 2.2) = 4,909091.
In fixed point:
10.8 (32bits Q24) => 0x0ACCCC;
2.2 (16bits Q8) => 0x0233;
(10.8 / 2.2) : (0x0ACCCC / 0X0233) = 0X0004E92C (result is Q16)
0x04E92C => 321836 decimal. Divided by 2^16 => 4,91082763671875
 
You see, in fixed point, the simple integer division is the worst operation, because it loses precision. Many applications will not suffer from this, because the result can still be in the required precision range. There are also other forms of division, that will not throw away the last remainder and will extend the result into more precision bits.
 
If you need to divide by a fixed number, use multiplication by the reciprocal of that number (1/number) instead.
 
Fixed point has another nicety: is is far easier and faster to convert to ASCII for display. Our number above, 0x04E92C would:
0x04 : integer part => convert 8bits binary to BCD: 0x04 => add 0x30 to each BCD digit: 0x30, 0x34
0xE92C : fractional part => multiply by 100 decimal (0x64) : (0xE92C * 0x64) = 0x5B1530. Take (0x5B) and convert to BCD => 0x91. Add 0x30 to each digit: 0x39, 0x31. Final ascii number 04,91.
 
 
Despite all the problems with accuracy, fixed point math is much faster than floating point math, and many realtime applications are based in fixed point to improve cycle time.
 
 
#33
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Confusing in the assembly language!!??(Beginer) 2006/03/08 14:27:37 (permalink)
0
Thank you very much!!Smile It is very detail and now I am clear to the fixed point number and conversion of BCD. grin
#34
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Confusing in the assembly language!!??(Beginer) 2006/03/13 13:19:27 (permalink)
0
May I know how to convert 16 bit value to bcd? As i know normally for 8 bit value I just subtract 100 or 10 to test it. But how could I do the convertion to the higher byte? Other than that, since the fixed point value is 32 bit, then 16 bit is the integer and 16 bit is the decimal place value. Is it I should do them seperately which is 16 bit each?
#35
lizarazu
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2006/03/29 19:13:38
  • Location: 0
  • Status: offline
RE: Confusing in the assembly language!!??(Beginer) 2006/03/29 19:22:35 (permalink)
0
what a gud advice..
#36
jbroadwell81@gmail.com
Super Member
  • Total Posts : 1460
  • Reward points : 0
  • Joined: 2005/11/02 13:58:11
  • Location: Indianapolis, Indiana
  • Status: offline
RE: Confusing in the assembly language!!??(Beginer) 2008/01/04 08:45:45 (permalink)
+1 (1)
Ping... keeping this thread alive.  Unfortunately,  most of jdoin's posts have been purged...

http://www.serialwombat.com
When someone asks you "Can't you just...", watch out.
#37
Page: < 12 Showing page 2 of 2
Jump to:
© 2021 APG vNext Commercial Version 4.5