OpenCores

Lightweight 8080 compatible core

Issue List
c80_lib #6
Closed andylgh opened this issue about 12 years ago
andylgh commented about 12 years ago

I think your ccdiv function in c80_lib is not correct?the example is following?

int tstary2 = {0xaabb, 0x99aa};

// sends a hexadecimal value to the UART printhex(hval) int hval; { char hbyte; char lbyte; char temp; hbyte = hval/256; //use the >>8 is ok lbyte = hval%256; //

sendbyte(hbyte);
sendbyte(lbyte);

temp = (hbyte & 0xf0)>>4;
if(temp > 9)
	sendbyte('a'+temp-10);
else
 	sendbyte('0'+temp);	
 	
temp = (hbyte & 0x0f);
if(temp > 9)
	sendbyte('a'+temp-10);
else
 	sendbyte('0'+temp);	
 	
temp = (lbyte & 0xf0)>>4;
if(temp > 9)
	sendbyte('a'+temp-10);
else
 	sendbyte('0'+temp);

temp = (lbyte & 0x0f);
if(temp > 9)
	sendbyte('a'+temp-10);
else
 	sendbyte('0'+temp); 		

}

printstr("Hex value: 0x"); printhex(tstary0); nl(); printstr("Hex value: 0x"); printhex(tstary1); nl();

the result of print as following?

received byte 0x30 ("0") at 1956000 ns

received byte 0x78 ("x") at 2053000 ns

received byte 0xab ("«") at 2270000 ns

received byte 0xbb ("»") at 2366000 ns

received byte 0x61 ("a") at 2461000 ns

received byte 0x62 ("b") at 2559000 ns

received byte 0x62 ("b") at 2654000 ns

received byte 0x62 ("b") at 2752000 ns

received byte 0x30 ("0") at 4112000 ns

received byte 0x78 ("x") at 4210000 ns

received byte 0x9a ("?") at 4427000 ns

received byte 0xaa ("ª") at 4522000 ns

received byte 0x39 ("9") at 4620000 ns

received byte 0x61 ("a") at 4717000 ns

received byte 0x61 ("a") at 4813000 ns

received byte 0x61 ("a") at 4911000 ns

motilito was assigned about 12 years ago
motilito commented about 12 years ago

When testing this bug report a different problem was found in the assembly code generated by the compiler. After fixing the problem, the bug could not be reproduced. Please check the updated compiler version (after it will be committed). Moti

andylgh commented about 12 years ago

think you for you reply rapidly! I update the compiler you have committed latest But the result is also the same:

the example is following?

int tstary2 = {0xaabb, 0x99aa};

// sends a hexadecimal value to the UART printhex(hval) int hval; { char hbyte; char lbyte; char temp; hbyte = hval/256; //use the >>8 is ok lbyte = hval%256; //

temp = (hbyte & 0xf0)>>4; if(temp > 9) sendbyte('a'+temp-10); else sendbyte('0'+temp);

temp = (hbyte & 0x0f); if(temp > 9) sendbyte('a'+temp-10); else sendbyte('0'+temp);

temp = (lbyte & 0xf0)>>4; if(temp > 9) sendbyte('a'+temp-10); else sendbyte('0'+temp);

temp = (lbyte & 0x0f); if(temp > 9) sendbyte('a'+temp-10); else sendbyte('0'+temp); }

printstr("Hex value: 0x"); printhex(tstary0); nl(); printstr("Hex value: 0x"); printhex(tstary1); nl();

the print result is :

received byte 0x30 ("0") at 1956000 ns

received byte 0x78 ("x") at 2053000 ns

received byte 0x61 ("a") at 2461000 ns

received byte 0x62 ("b") at 2559000 ns

received byte 0x62 ("b") at 2654000 ns

received byte 0x62 ("b") at 2752000 ns

received byte 0x30 ("0") at 4112000 ns

received byte 0x78 ("x") at 4210000 ns

received byte 0x39 ("9") at 4620000 ns

received byte 0x61 ("a") at 4717000 ns

received byte 0x61 ("a") at 4813000 ns

received byte 0x61 ("a") at 4911000 ns

I think the problem happen in your "ccdiv" function of c80_lib ????????????????????

motilito commented about 12 years ago

This was a great riddle to solve. There is no bug in the compiler. In the above example the usage of shift right by 8 works (>>8) but division by 256 does not. The cause of the problem is that the div function is implemented SIGNED. The values in the example above are signed and the results are correct. Example:

0xaabb = 43707 UNSIGNED 43707 SIGNED = 43707 - 2^16 = -21829 -21829 / 256 = |-85.269...| = -85 -85 SIGNED = -85+256 = 171 UNSIGNED = 0xab !!!!!!

And thus the text printed to the UART for an integer value of 0xaabb is 0xabbb. The same is also true for the second value 0x99aa. Moti

motilito closed this about 12 years ago

Assignee
motilito
Labels
Bug