Jump to content

Pairwise sums of elements of the array

- - - - -

  • Please log in to reply
1 reply to this topic

#1
Sega

Sega

    Newbie

  • Members
  • Pip
  • 5 posts
Hello

Help me please:
Through a comma introduces an array of two-digit values, by pressing "=" displays the pairwise sum of array elements (first+second,second+third ...)

i8080 (emulator z80 and linker L80)

I have a program for addition of three two-digit numbers (can be this program as that to change for my case):
 

;exp:

;       12+10+22=44

;       99+99+99=297

 

jmp start

 

n1:             db      00h, 00h

n2:             db      00h, 00h

n3:             db      00h, 00h

plus1:          db      00h

plus2:          db      00h

equals:         db      00h

;onemoredigit:  db      00h

 

;============================================

;       MAIN PROGRAM

;============================================

start:

 

;read 3 numbers

        call    read            ; N1    

        call    check_dec               ; then check 

        pop     b

        jnc     error

        sui     '0'     ;       if  not error then convert ascii to hex

        sta     n1+1    ;       save

 

        call    read    

        call    check_dec

        jnc     error

        sui     '0'     ;       if  not error then convert ascii to hex

        sta     n1

 

        call    read            ;+

        sui     '+'     ;       ascii  '+'

        jnz     error

 

        call    read            ;N2

        call    check_dec

        jnc     error

        sui     '0'     ;       if  not error then convert ascii to hex

        sta     n2+1

 

        call    read

        call    check_dec

        jnc     error

        sui     '0'     ;       if  not error then convert ascii to hex

        sta     n2

 

        call    read

        sui     '+'     

        jnz     error

 

        call    read            ;N3

        call    check_dec

        jnc     error

        sui     '0'     ;       if  not error then convert ascii to hex

        sta     n3+1

 

        call    read            

        call    check_dec

        jnc     error

        sui     '0'     ;       if  not error then convert ascii to hex

        sta     n3

 

        call    read            ;=

        sui     '='     

        jnz     error

 

;CALCULATE SUM OF 3 NUMBERS     save to de and n1, n1+1

start_sum:

        lda     n1

        mov     b, a    

        lda     n2

        add     b

        mov     b, a

        lda     n3

        add     b

 

        call    todecimal

        mov     a, e

        adi     '0'

        sta     n1

        

        lda     n1+1

        mov     b, a

        lda     n2+1

        add     b

        mov     b, a

        lda     n3+1

        add     b

        add     d

        

        call    todecimal

        mov     a, e

        adi     '0'

        sta     n1+1

 

        mvi     a, 00h

        add     d

        adi     '0'

                ;sta    onemoredigit

        

;result 

        mvi     b, '0'

        cmp     b

        jz      skipzeroprint

        call    print

           skipzeroprint:

        lda     n1+1

        call     print          

        lda     n1

        call    print

        jmp     exit    

        

;============================================

;       CONVERT BYTE TO DECIMAL DIGIT AND SUM OF OVERFLOWS

;============================================

todecimal:

        ;       input byte              a

        ;       uses            d, e, a

        ;       return          d:e, e<9h

        mvi     d, 00h

          loop:

        mov     e, a

        mvi     a, 9h   ; esli bol'she 9 to ...

        cmp     e

        mov     a, e

        jnc     nooverflow

        sui     0Ah     ; +6h -10h = Ah

        inr     d

        jmp     loop

          nooverflow:

        ret

 

;============================================

;       READ ONE BYTE FROM SCREEN

;============================================

read:

        ;       return one byte in      a

        push    b

        push    h

        mvi     c, 01h

        call    0005h

        pop     h

        pop     b

        ret

 

;============================================

;       PRINT ONE BYTE TO SCREEN

;============================================

print:

        ;       data is A

        push    b

        push    d

        push    h

        push    psw

        mov     e, a

        mvi     c, 02h

        call    0005h

        pop     psw

        pop     h

        pop     d

        pop     b

        ret

 

;============================================

;       CHECK IF BYTE IS A DEC DIGIT

;============================================

check_dec:

        ;               byte is in              a

        ;               uses            a, b

        ;               return          cf=hex  ncf=not a digit

    digit:

        mvi     b, 30h

        cmp     b

        jc      nodig

        mvi     b, 40h

        cmp     b

        jnc     nodig

        stc             ;       set cf  cf=1

        ret

     nodig:

        stc     ;       set cf

        cmc     ;       invert cf               cf=0

        ret

 

;============================================

;       END

;============================================

error:

        mvi     a, 3Fh  ;       ascii '?' 

        call    print

exit:

        ;mvi    a, 0Dh  ;print  something on exit

        ;call   print

        ret

 

END


#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
So what's your problem? Can you be more specific?
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users