Assembly LOVEPOPA's UNIVERSE
of FREE Atari source listings !!

AVERAGE.S


*********************************
*         AVERAGE.S             *
*       (C) 6/20/1991           *
*           by PKF              *
*********************************

PRINT   MACRO   adr_s
        pea     \1
        move.w  #9,-(sp)        _cconws
        trap    #1
        addq.w  #6,sp
        ENDM

*********************************
        SECTION TEXT
*********************************

        PRINT   msg_0

prgcyc: add.l   #1,num_c

        PRINT   msg_1

        move.l  num_c,d3
        jsr     hexdec          *** input in D3

        PRINT   msg_2

        pea     buf_s
        move.w  #10,-(sp)       _cconrs
        trap    #1
        addq.w  #6,sp

        jsr     dechex          *** output in D2
        cmp.l   #$FFFFFFFF,d2
        beq     endprg
        add.l   d2,sum_t

        PRINT   msg_3

        move.l  sum_t,d2
        move.l  num_c,d4
        clr.l   d3

cyc_1:  sub.l   d4,d2
        add.l   #1,d3
        cmp.l   d4,d2
        bge     cyc_1           *** D2=remainder  D3=quotient

        move.l  d2,d6
        jsr     hexdec
        cmp.l   #0,d6
        beq     prgcyc

        move.w  #$2C,-(sp)
        move.w  #2,-(sp)        _cconout
        trap    #1
        addq.w  #4,sp

        move.l  #9,d7

cyc_4:  move.l  num_c,d4
        clr.l   d2
        move.w  #9,d3
cyc_2:  add.l   d6,d2
        dbf     d3,cyc_2
        clr.l   d3

cyc_3:  sub.l   d4,d2
        add.l   #1,d3
        cmp.l   d4,d2
        bge     cyc_3           *** D2=remainder  D3=quotient

        move.l  d2,d6
        jsr     hexdec
        cmp.l   #0,d6
        beq     out_4
        dbf     d7,cyc_4

out_4:  bra     prgcyc

endprg: move.w  #0,-(sp)        _ptermold
        trap    #1

******************************* SUBROUTINES

hexdec: clr.l   d2
        lea     dec_n,a3        *   hex2dec.s
        lea     dec_t,a4        * (C) 1/23/1991
        move.l  (a4)+,d4        * max $BB9AC9FF
        clr.l   (a3)
        clr.l   4(a3)
        clr.l   8(a3)

lop_1:  sub.l   d4,d3
        bmi     out_1
        add.b   #1,d2
        bra     lop_1

out_1:  move.b  d2,(a3)+
        clr.b   d2
        add.l   d4,d3
        move.l  (a4)+,d4
        cmp.l   #0,d4
        bgt     lop_1

        lea     dec_n,a3
        or.l    #$30303030,(a3)+
        or.l    #$30303030,(a3)+
        or.w    #$3030,(a3)
        sub.w   #8,a3
lop_2:  cmp.b   #$30,(a3)+
        beq     lop_2
        sub.w   #1,a3

        move.l  a3,-(a7)
        move.w  #9,-(a7)        _cconws
        trap    #1
        addq.w  #6,a7
        rts

****************

dechex: move.l  #10,d2
        move.b  buf_s+1,d3
        lea     dec_t,a4
        sub.b   d3,d2
        mulu    #4,d2
        add.w   d2,a4
        move.l  (a4)+,d4
        clr.l   d5
        lea     buf_s+2,a5
        move.b  (a5)+,d5

        cmp.b   #$39,d5
        bgt     out_3
        cmp.b   #$30,d5
        blt     out_3

        sub.b   #$30,d5
        clr.l   d2

lop_3:  sub.b   #1,d5
        bmi     out_2
        add.l   d4,d2
        bra     lop_3

out_2:  sub.b   #1,d3
        cmp.b   #0,d3
        beq     out_3

        move.l  (a4)+,d4
        move.b  (a5)+,d5

        cmp.b   #$39,d5
        bgt     skp_1
        cmp.b   #$30,d5
        blt     skp_1

        sub.b   #$30,d5
        bra     lop_3

skp_1:  move.l  #$FFFFFFFF,d2

out_3:  rts



********************************
        SECTION DATA
********************************

msg_0:  dc.b    'AVERAGE.S  --  (C) 6/20/1991, by PKF',$00
msg_1:  dc.b    $0D,$0A,$0D,$0A,'Please input the ',$00
msg_2:  dc.b    'th number (neg=end): ',$00
msg_3:  dc.b    $0D,$0A,'Current average is: ',$00
dec_t:  dc.l    $3B9ACA00,$5F5E100,$989680,$F4240
        dc.l    $186A0,$2710,$3E8,$64,$A,$1,$0
buf_s:  dc.b    6,0
        ds.b    6



********************************
        SECTION BSS
********************************

num_c:  ds.l    1
dec_n:  ds.l    3
sum_t:  ds.l    1

- MAIL TO ME -

Web design by PKF - 2001 -
Hosted by www.Geocities.ws

1