| 008 20.01.2020, 20:14 Uhr
 holm
 
 
   
 
 | Beispiel: Testprogramm tt.c:
 
 
 
 | Quellcode: |  | #include <stdio.h>
 
 char buf[128];
 
 main()
 {
 
 buf[0]='Y';
 
 #asm
 global jjj
 jjj: ld hl,_buf
 ld a,(hl)
 out (027H),a
 #endasm
 
 printf("Hallo!\r\n");
 }
 
 | 
 
 
 Übersetzung ohne Optimizer:
 c -s tt.c, ergibt tt.as
 
 
 | Quellcode: |  | (jede Menge Kommentar gelöscht)
 ;stdio.h: 90: extern    struct _iobuf * fdopen(int, char *);
 ;stdio.h: 91: extern long       ftell(  struct _iobuf *);
 ;stdio.h: 92: extern char *     fgets(char *, int,      struct _iobuf *);
 ;stdio.h: 93: extern char *     _bufallo(void);
 ;TT.C: 3: char buf[128];
 ;TT.C: 5: main()
 ;TT.C: 6: {
 psect   text
 global  _main
 _main:
 global  ncsv, cret, indir
 call    ncsv
 defw    f30
 ;TT.C: 8: buf[0]='Y';
 ld      a,.low.89
 ld      (_buf),a
 global jjj
 ;TT.C: 11: global jjj
 jjj: ld hl,_buf
 ;TT.C: 12: jjj: ld hl,_buf
 ld a,(hl)
 ;TT.C: 13:      ld a,(hl)
 out (027H),a
 ;TT.C: 14:      out (027H),a
 ;TT.C: 17: printf("Hallo!\r\n");
 global  _printf
 ld      hl,19f
 push    hl
 call    _printf
 ld      hl,2
 add     hl,sp
 ld      sp,hl
 ;TT.C: 18: }
 l2:
 jp      cret
 f30     equ     0
 psect   data
 19:
 defb    72,97,108,108,111,33,13,10,0
 psect   bss
 _buf:
 defs    128
 
 
 | 
 
 
 ..so weit, so hübsch, bist auf die Tatsache das 0x27 statt 027H nicht funktioniert (entgegen der Doku), ok geschenkt.
 Läßt man das mit Optimizer laufen:
 
 
 
 | Quellcode: |  | K>c -O -V tt.c
 HI-TECH C COMPILER (CP/M-80) V3.09
 Copyright (C) 1984-87 HI-TECH SOFTWARE
 0:CPP -DCPM -DHI_TECH_C -Dz80 -I TT.C $CTMP1.$$$
 0:P1 $CTMP1.$$$ $CTMP2.$$$ $CTMP3.$$$
 0:CGEN $CTMP2.$$$ $CTMP1.$$$
 0:OPTIM $CTMP1.$$$ $CTMP2.$$$
 0:ZAS -J -N -oTT.OBJ $CTMP2.$$$
 $CTMP2.$$$:12:  Syntax error
 ERA $CTMP1.$$$
 ERA $CTMP2.$$$
 ERA $CTMP3.$$$
 ERA TT.OBJ
 ERA $$EXEC.$$$
 
 | 
 
 
 ..kracht es auf Zeile 12. Nachforschungen ergeben dann, das das die Ausgabe von A nach 0x27 ist, der Optimizer scheint den Befehl gar nicht zu kennen...
 
 Ich kann den selben Code aber in ein AS File schreiben und ZAS vorwerfen, es wird sauber ein OBJ gebaut, das sich mit LINQ auch zum C-Code linken läßt.
 
 Nochmal einzeln die Dateien vor und nach Optim:
 
 
 | Quellcode: |  | K>type $CTMP1.$$$
 psect   text
 global  _main
 _main:
 global  ncsv, cret, indir
 call    ncsv
 defw    f30
 global  _buf
 ld      a,.low.89
 ld      (_buf),a
 global jjj
 jjj: ld hl,_buf
 ld a,(hl)
 out (027H),a
 global  _printf
 ld      hl,19f
 push    hl
 call    _printf
 ld      hl,2
 add     hl,sp
 ld      sp,hl
 l2:
 jp      cret
 f30     equ     0
 psect   data
 19:
 defb    72,97,108,108,111,33,13,10,0
 psect   bss
 _buf:
 defs    128
 
 | 
 
 
 nach optim:
 
 
 | Quellcode: |  | global  _main
 global  ncsv, cret, indir
 global  _buf
 global  jjj
 global  _printf
 psect   text
 _main:
 ld      a,89
 ld      (_buf),a
 ld      hl,_buf
 ld      a,(hl)
 hl      39
 ld      hl,19f
 push    hl
 call    _printf
 pop     bc
 ret
 psect   data
 19:
 defb    72,97,108,108,111,33,13,10,0
 psect   bss
 _buf:
 defs    128
 psect   text
 
 | 
 
 
 Aus  "out(027H),a"   ist     "hl  39"    geworden... ich kanns dem ZAS nicht übel nehmen wenn der darüber nörgelt.
 
 Gruß,
 Holm
 --
 float R,y=1.5,x,r,A,P,B;int u,h=80,n=80,s;main(c,v)int c;char **v;
 {s=(c>1?(h=atoi(v[1])):h)*h/2;for(R=6./h;s%h||(y-=R,x=-2),s;4<(P=B*B)+
 (r=A*A)|++u==n&&putchar(*(((--s%h)?(u<n?--u%6:6):7)+"World! \n"))&&
 (A=B=P=u=r=0,x+=R/2))A=B*2*A+y,B=P+x-r;}
 Dieser Beitrag wurde am 20.01.2020 um 21:01 Uhr von holm editiert.
 |