Menu

#2320 incorrect code generated for z80

closed-fixed
None
Z80
7
2014-12-27
2014-11-26
Tommy Thorn
No

In the attached code, the computation of

buffer + buffer_size - buffer_len + buffer_p

is miscomputed by sdcc 3.4.0

(compiled with
sdcc --std-c99 -mz80 --code-loc 0x1004 --data-loc 0x4000 --no-std-crt0 crt0_nascom.rel)

;demos/nasmacs.c:105: buffer + buffer_size - buffer_len + buffer_p,
ld a,(#_buffer + 0)
add a, #0xFE
ld e,a
ld a,(#_buffer + 1)
adc a, #0x1F
ld d,a
ld hl,(_buffer_len)
ld a,e
sub a, l
ld l,a
ld a,d
sbc a, h

    ;; So far <a,l> is the running sum

    ld      a,l     ;; <--- Huh, this is overriding the just computed value         
    ld      hl,#_buffer_p                                                           
    add     a, (hl)                                                                 
    ld      e,a                                                                     
    ld      a,h                                                                     
    inc     hl                                                                      
    adc     a, (hl)                                                                 
    ld      d,a
1 Attachments

Discussion

  • Philipp Klaus Krause

    The underlying problem is a hl issue again: In between the sbc a, h and the ld a, l there was a ld h, a. This got optimized out, because the compiler recognized that h got overwritten by the ld hö, #_buffer_p later on.

    Philipp

     
  • Philipp Klaus Krause

    • Category: other --> Z80
     
  • Philipp Klaus Krause

    • Priority: 5 --> 7
     
  • Philipp Klaus Krause

    I can reproduce this in current svn.

    Philipp

     
  • Philipp Klaus Krause

    • assigned_to: Philipp Klaus Krause
     
  • Philipp Klaus Krause

    • status: open --> closed-fixed
     
  • Philipp Klaus Krause

    Fixed in revision #9148.

    Philipp

     

Log in to post a comment.