Let's run once as one example, b[] is "3c 08 00 01 ....." ,step=4, bidx=0,
bc=0x1000if run this code for (j = step; j > 0 && bc > 0; j--)
{ if (urj_big_endian) { data
|= b[bidx++]; data <<= 8; }then there are 4
loops1st: data |= b[bidx++]; data = 0x3c
data <<= 8; data =
0x3c002nd: data |= b[bidx++]; data = 0x3c08
data <<= 8; data =
0x3c08003rd: data |= b[bidx++]; data =
0x3c0800 data <<=
8; data = 0x3c0800004th: data |=
b[bidx++]; data = 0x3c080001 data <<=
8; data = 0x08000100then at the end,
get 0x08000100, so we lost the first byte 0x3canything wrong ?----- 原文 -----
发件人: Rutger Hofman 主 题: Re: [UrJTAG-dev] Is there a bug in writemem.c for big
endian ?时 间: 2009年11月16日 18时33分51秒抄 送:
[email protected], Snowel Xue wrote:> Hi > I found
there is one bug here:> orignal code:> /* Write a word at a time
*/> data = 0; for (j = step; j > 0 && bc > 0;
j--)> {> if (urj_big_endian)> {
> data |= b[bidx++];> data <<=
8;> }> else> data |=
(b[bidx++] << ((step - j) * 8));> bc--;> }>
it should move "data <<= 8;" before "data |= b[bidx++];", or else, it
cause one byte overflow.> the correct code should be:> > /*
Write a word at a time */> data = 0;> for (j = step; j
> 0 && bc > 0; j--)> {> if
(urj_big_endian)> {> data <<= 8;>
data |= b[bidx++];> }> else>
data |= (b[bidx++] << ((step - j) * 8));>
bc--;> }Hmmm. I don't see the bug. After the loop, variable data
points past the array, but that is no problem because it is not accessed. In
your fix, the first byte of data is not written.RutgerBest Regards------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
UrJTAG-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/urjtag-development