From: Bernie R. <ra...@sp...> - 2002-03-27 19:02:54
|
Hello I have been using the SDCC compiler and have had good results with it. I have come across a problem that I can't understand. If you could, I would be a great benefit if you could help me with an answer. I am using version version 2.3.0 of sdcc. I am having a problem with creating a 16 bit interger from 2 8 bit bytes. I am writing in C. below is the snippet of the working and non-working C and the resulting assembly code generated by the asx8051 assembler. As a summary of my problem, SETUPDAT[3] holds 0x1F and SETUPDAT[2] holds 0xFF. I want to combine these two bytes into a word variable that is at r2,r3 in order to produce 0x1FFF. The WORKING code does it but the NOT WORKING code results in 0x1EFF. I have marked with an '*' the only lines of assembly code that are different. (I didn't have much luck discovering what rlc followed by subb were doing.) WORKING: addr = SETUPDAT[3]; addr <<= 8; addr += (SETUPDAT[2] & 0xFF); 1692 ; src/ezusb.c 586 067E 1693 00162$: 067E 90 7F EB 1694 mov dptr,#(_SETUPDAT + 0x0003) 0681 E0 1695 movx a,@dptr 1696 ; Peephole 105 removed redundant mov 0682 FA 1697 mov r2,a 0683 33 1698 rlc a 0684 95 E0 1699 subb a,acc 0686 FB 1700 mov r3,a 1701 ; src/ezusb.c 587 0687 8A 03 1702 mov ar3,r2 0689 7A 00 1703 mov r2,#0x00 1704 ; src/ezusb.c 588 068B 90 7F EA 1705 mov dptr,#(_SETUPDAT + 0x0002) 068E E0 1706 movx a,@dptr 068F FC 1707 mov r4,a * 0690 7D 00 1708 mov r5,#0x00 0692 EC 1709 mov a,r4 0693 2A 1710 add a,r2 0694 FA 1711 mov r2,a 0695 ED 1712 mov a,r5 0696 3B 1713 addc a,r3 0697 FB 1714 mov r3,a NOT WORKING: addr = SETUPDAT[3]; addr = addr << 8; addr += SETUPDAT[2]; 1692 ; src/ezusb.c 586 067E 1693 00162$: 067E 90 7F EB 1694 mov dptr,#(_SETUPDAT + 0x0003) 0681 E0 1695 movx a,@dptr 1696 ; Peephole 105 removed redundant mov 0682 FA 1697 mov r2,a 0683 33 1698 rlc a 0684 95 E0 1699 subb a,acc 0686 FB 1700 mov r3,a 1701 ; src/ezusb.c 587 0687 8A 03 1702 mov ar3,r2 0689 7A 00 1703 mov r2,#0x00 1704 ; src/ezusb.c 588 068B 90 7F EA 1705 mov dptr,#(_SETUPDAT + 0x0002) 068E E0 1706 movx a,@dptr 1707 ; Peephole 105 removed redundant mov 068F FC 1708 mov r4,a * 0690 33 1709 rlc a * 0691 95 E0 1710 subb a,acc * 0693 FD 1711 mov r5,a 0694 EC 1712 mov a,r4 0695 2A 1713 add a,r2 0696 FA 1714 mov r2,a 0697 ED 1715 mov a,r5 0698 3B 1716 addc a,r3 0699 FB 1717 mov r3,a -- | Bernie Radecki SA PGU R&D Firmware Engineer | | Agilent Technologies e_mail: ra...@ag... | | 24001 East Mission Ave., MS 3WU/222 phone: (509)921-3655 | | Liberty Lake, WA. 99019-9599 fax: (509)921-3991 | ====================================================================== |