-3

This code is meant to find the sum of numbers stored in an array. The result is symbol to be printed in ASCII. How do I print the text number instead of the symbol?

.MODEL SMALL

.stack 100h

.DATA

 ARR db 10,20,30,40,50
sum db 0      
 
.CODE

    main proc
        mov ax,@data
        mov ds,ax
        
        mov cx,5
        mov ax,0
        mov bx,offset ARR
        
       repeat:add al,[bx]
        inc bx
        dec cx
        jnz repeat
        mov sum,al
     
        mov dl,sum
        mov ah,sum 
        
        mov ah, 02h
        int 21h
       
     main endp

END main

What do I need to change and add?

Thomas Jager
  • 4,836
  • 2
  • 16
  • 30
  • 1
    You posted the same question yesterday and it's still a duplicate: you have to split large numbers into multiple decimal digits, each one of which is a separate character to print on the screen. Use a debugger to look at numbers in registers. (Also, you're missing an exit system call after printing ASCII code `150`; execution will fall off the end of your `main`.) – Peter Cordes Jul 29 '20 at 16:07

1 Answers1

0

I think you made a mistake in printing the sum value. Please try this one.

.MODEL SMALL

.stack 100h

.DATA

sum_str db 3 dup(0)
 ARR db 10,20,30,40,50
 
.CODE

    main proc
        mov ax,@data
        mov ds,ax
        
        mov cx,5
        mov ax,0
        mov bx,offset ARR
        
       repeat:add al,[bx]
        inc bx
        dec cx
        jnz repeat
       
       mov cx, 3
       mov dx, offset sum_str
       loop:
         mov ah, 0
         mov bl, 10
         div bl
         mov bl, ah
         add bl, 30h
         mov [dx], bl
         inc dx
         dec cx
         jnz loop

       mov cx, 3
       loop1: 
          mov dx, offset sum_str
          add dx, cx
          dec dx
          mov dl, [dx]
          mov ah, 02h
          int 21h
          dec cx
          jnz loop1
     main endp

END main
Kungfu Frog
  • 81
  • 1
  • 8