#1528 Code generation bug: accesses incorrect code memory address


Attached is a zip of the program (bug.c) that reproduces the problem, with a comment (starting with **BUG**) in the bug.rst file describing the problem. The bug.c file is also commented with a couple of notes.

I encountered this bug on the latest release version but confirmed it still exists in the latest snapshot.
The code was simply compiled with: sdcc bug.c
The attached code was compiled with the latest sdcc snapshot:
SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.9.1 #5427 (Apr 5 2009) (UNIX)

Please contact me if you need more info jonkuhn at gmail

Here is the snippet from the bug.rst file:

; **BUG**
; Here _b is at (code memory) 0x0121, and 0x0121+0xC0 = 0x01E1
; The result of the add instruction is that a = 0x21 (0x40 + 0xe1) which is
; correct, but the carry will be set, which means that the result of the
; the addc instruction is that a = 0x02 (0x00 + 0x01 + Carry)
; Therefore when the movc instruction is executed it will get data from
; 0x0221 instead of 0x0121

00B8 24 E1 210 add a,#0xc0+_b
00BA F5 82 211 mov dpl,a
00BC E4 212 clr a
00BD 34 01 213 addc a,#(_b >> 8)
00BF F5 83 214 mov dph,a
00C1 E4 215 clr a
00C2 93 216 movc a,@a+dptr


  • jonkuhn

    jonkuhn - 2009-04-06

    Code to reproduce the bug.

  • Frieder Ferlemann

    • status: open --> closed-fixed
  • Frieder Ferlemann

    fixed in #5428

  • Borut Ražem

    Borut Ražem - 2009-04-06
    • milestone: --> fixed
    • assigned_to: nobody --> frief

Log in to post a comment.