0

I am working on an assembly assignment for school. The objective is to take two numbers from user input, add them and then output the result on screen. However, the array, output, that holds the results of the operations to be outputted will not print out to the screen whatsoever. I am really not sure exactly what is wrong here. My print_output function works as a whole since it will print out other strings and arrays if I tell it to do so. Due to this I think I might have an indexing issue with accessing the input array for the data need for the operations that causes issues later or maybe something with my arithmetic but that is really my only hunch. Thanks for any help with this. Note: In response to Michael's comment I edited the program back for the array to terminate in a $ but the problem was still occuring past that.

.model small
.stack 64
    .data

Prompt     DB    'Enter a number between 10 and 49 number:  ', '$'
Prompt2    DB    'Enter another number between 10 and 49 number:  ', '$'
StrPar     LABEL BYTE
StrPar2    LABEL BYTE
Actual_Len DB    4 
Chars      DB    4 DUP('$')
output     DB    4 DUP('$')

    .code

MAIN proc FAR
     mov  AX,@data
     mov  DS,AX

     call Clear
     call Set_Cursor
     call Request_Input
     call Get_Input
     call Add_Input  
     call Clear
     call Set_Cursor
     call Request_Input2
     call Get_Input
     call Clear
     call Set_Cursor
     call Add_Input2    
     call Prep_Output
     call Print_Output 
     
   
   
    

     mov  AX,4C00h
     int  21h

MAIN  endp

;________________________

Clear proc NEAR 
      mov AX, 06H
      mov AL, 00H
      mov BH, 71H
      mov CX, 0000H
      mov DX, 184FH
      int 10H
      ret
Clear endp

;__________________________

Set_Cursor proc NEAR
    mov AH, 02H
    mov BH, 0
    mov DH, 10
    mov DL, 5
    int 10H
    ret
Set_Cursor endp
;___________________________

Request_Input proc NEAR
    mov AH, 09H
    lea DX,Prompt
    int 21H
    ret
Request_Input endp

;___________________________

Request_Input2 proc NEAR
    mov AH, 09H
    lea DX,Prompt2
    int 21H
    ret
Request_Input2 endp

;__________________________

Get_Input proc NEAR
    mov AH, 0AH
    lea DX, StrPar
    int 21H
    mov BH,00
    mov BL,Actual_Len
    mov Chars[BX],'$'
        ret
Get_Input endp
;__________________________


;_________________________


Add_Input proc NEAR 
    mov AH, 00
    mov DX, 00
    mov BX,1
    mov DL, Chars[BX]
    sub DL,48 
    mov AX,10
    mul DX
    mov DX,AX
    mov BX,2
    mov CX,00
    mov CL, Chars[BX]
    sub CX,48 
    add DX,CX
    ret
Add_Input endp
;______________________
Add_Input2 proc Near
    mov AX,00
    mov BX,1
    mov CL, Chars[BX]
    sub CX, 48 
    mov AX,10
    mul CX
    mov CX,AX
    mov BX,2
    mov BL, Chars[BX]
    sub BL,48
    mov BH,00
    add CX,BX
    ret
Add_Input2 endp
;______________________
Prep_Output proc NEAR
    mov AX,00
    add DX,CX 
    mov AX,DX
    mov BX,10 
    div BL
    add AL,48
    add AH,48
    mov BX, 1   
    mov output[BX],AL
    mov BX, 2
    mov output[BX],AH
     
    ret

Prep_Output endp


;________________________
Print_Output proc NEAR
    mov AH, 09H
    lea DX, output
    int 21H 
    
        ret 
    
    

Print_Output endp



end MAIN


  • 2
    `int 21h / ah=09h` expects the string to be terminated by a `'$'`-character. – Michael May 10 '21 at 13:45
  • 1
    Possible duplicate with different symptoms for the same missing-$ problem: [Weird garbage in output](https://stackoverflow.com/q/19299433) – Peter Cordes May 10 '21 at 13:52
  • 1
    I notice that `prep_output` only writes the 2nd and 3rd bytes (`output[1]` and `[2]`). What's in memory pointed-to by DS:DX right before that `int 21h`? (Use a debugger to single-step.) With your update, if you leave the first character as a `$`, then you're printing the empty string. – Peter Cordes May 10 '21 at 13:54
  • I guess a more specific duplicate would be about array indexing starting from 0 in your int->string function. [Displaying Time in Assembly](https://stackoverflow.com/q/37129794) doesn't store to form a string, but [Assembly, printing ascii number](https://stackoverflow.com/a/15621644) shows a loop that stores into a buffer. – Peter Cordes May 10 '21 at 14:02

0 Answers0