From: SourceForge.net <no...@so...> - 2007-12-04 11:26:07
|
Bugs item #1843320, was opened at 2007-12-03 13:47 Message generated for change (Settings changed) made by drdani You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1843320&group_id=599 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Simulator Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: threinbacher (threinbacher) >Assigned to: Daniel Drotos (drdani) Summary: ucsim: ADD/ADDC Command: PSW is not set correct! Initial Comment: Hi All, I'm pretty sure that there exists a bug concerning the PSW value after an ADD instruction. I assume that this bug exists in the ADDC instruction as well. Example: While executing the 63th instruction of the attached *.hex file the PSW is not set correct: The instruction is: 0x0a51 24 fa -> which is a: ADD A,#data instruction situation: A: 0x09 #data: 0xFA PSW: 0x00 now the Instruction 0x24 = ADD A,#data is executed: in binary: #data: 11111010 A 00001001 ___________________+ res: 100000011 Now the ucSim sets the PSW to 0xC0: 0xC0 = 11000000 => CY=1, AC=1, OV=0 but it should be: 0x84 = 10000100 => CY=1, AC=0, OV=1 to set the PSW after an ACC instruction IMHO it should be done according to following code fragment: tmp3 = current Accumulator Value. /** Set Carry Flags * */ /** CY: Check if there is a carry-out at bit 7 */ if (((tmp3 & 0x100 == 0x100)){ mcu.psw.bitSet(C51PSW.FLAG_CY); } else { mcu.psw.bitClear(C51PSW.FLAG_CY); } /** AC: Check if there is a carry-out at bit 7 */ if (((tmp3 & 0x10) == 0x10)){ mcu.psw.bitSet(C51PSW.FLAG_AC); } else { mcu.psw.bitClear(C51PSW.FLAG_AC); } /** Check if Overflow Bit should be set */ if (((tmp3 & 0x80) == 0x80) && ((tmp3 & 0x100) != 0x100)) { mcu.psw.bitSet(C51PSW.FLAG_OV); } else if(((tmp3 & 0x100) == 0x100) && ((tmp3 & 0x80) != 0x80)){ mcu.psw.bitSet(C51PSW.FLAG_OV); } else { mcu.psw.bitClear(C51PSW.FLAG_OV); } According to INTEL 8051 user manual and 8052.com flag setting after an ADD/ADDC instruction should be done in this way: The Carry bit (C) is set if there is a carry-out of bit 7. In other words, if the unsigned summed value of the Accumulator, operand and (in the case of ADDC) the Carry flag exceeds 255 Carry is set. Otherwise, the Carry bit is cleared. The Auxillary Carry (AC) bit is set if there is a carry-out of bit 3. In other words, if the unsigned summed value of the low nibble of the Accumulator, operand and (in the case of ADDC) the Carry flag exceeds 15 the Auxillary Carry flag is set. Otherwise, the Auxillary Carry flag is cleared. The Overflow (OV) bit is set if there is a carry-out of bit 6 or out of bit 7, but not both. In other words, if the addition of the Accumulator, operand and (in the case of ADDC) the Carry flag treated as signed values results in a value that is out of the range of a signed byte (-128 through +127) the Overflow flag is set. Otherwise, the Overflow flag is cleared. lg from Vienna, Thomas ---------------------------------------------------------------------- Comment By: threinbacher (threinbacher) Date: 2007-12-04 00:34 Message: Logged In: YES user_id=1949775 Originator: YES Hi all, Just now i simulated the exact Program Code with the Keil C51 Simulator. And Keil behaves exactly like ucsim in this case, but Why?? Can somebody give me a hint how the 8051 sets its flag after an ADD instruction?? In my opinion the datasheet of ther 8051 specifies this in exaclty the other way.... lg from Vienna, Thomas ---------------------------------------------------------------------- Comment By: threinbacher (threinbacher) Date: 2007-12-03 14:56 Message: Logged In: YES user_id=1949775 Originator: YES Some more infos: Im using the ucsim S51 that is delivered with sdcc version: sdcc-snapshot-i386-unknown-linux2.5-20071202-4974 My kernel Version is: 2.6.22.5-31-default | opensuse 10.3 lg Thomas ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1843320&group_id=599 |