CompuServe Messages

#"C" users read Pascal?

    07-Sep-86 13:33:09
Fm: Jim Mischel 73717,1355
To: Tom Cattrall 72767,622
Tom, It looks like Turbo Pascal could use some real improvement in the code it generates. I compiled this on a Z80 version of Turbo. To tell you the truth, I'm not impressed. I used to think that Turbo did a good job of optimization. ; program test; type anarray = array [1..100] of integer; var i, n : integer; array1, array2, array3 : anarray; begin n := 100; for i := 1 to n do array1[i] := array2[i] + array3[i]; end. ; ; the loopset routine is called by every for loop before the first ; iteration. it returns the number of iterations in de and the initial ; value of the loop index variable in hl. ; loopset: or a sbc hl,de ex de,hl inc de jp pe,.ls1 ret p jr .ls2 ls1: ret m ls2: ld de,0 ret start: ld hl,100 ld (n),hl ;n=100 ld hl,1 push hl ld hl,(n) pop de call loopset ;loop setup returns hl=start,de=#iterations loop: ld a,d or e jp z,done ;if de=0, we're done push de ;save loop counter ld (i),hl ; ld hl,array1 ;array1 base push hl ld hl,(i) ;loop index dec hl add hl,hl ;hl=array offset pop de ;de=base address add hl,de push hl ;save destination ld hl,array2 ;array2 base push hl ld hl,(i) ;loop index dec hl add hl,hl ;hl=offset pop de ;de=base add hl,de ;points to operand ld e,(hl) inc hl ld d,(hl) ;operand in de ex de,hl push hl ;first operand on stack ld hl,array3 ;array3 base push hl ld hl,(i) dec hl add hl,hl pop de add hl,de ;points to operand ld e,(hl) inc hl ld d,(hl) ;operand in de ex de,hl ;to hl pop de ;restore first operand add hl,de ;hl = array[2] + array[3] ex de,hl ;de = " " pop hl ;hl = destination address ld (hl),e inc hl ld (hl),d ;and it's saved ld hl,(i) inc hl ;i = i+1 pop de dec de ;decrement loop counter jp loop ;and go again done: <continued in next message>