Search code examples
assemblyasciidosx86-16emu8086

Output Twice in Assembly Language 8086


I almost solve my problem in assembly language. However the capitalize part shows double and has a space above it. It should only show ones. When i type "i am from burma" the capitalize part works but it has a space above it and it outputs twice. How can i fix this?

Current Result i

Expected Result

Enter string: i am from burma
a am from burma
I am from burma

Code

.MODEL SMALL
.STACK 100H

.DATA
    INPUT_STRING          DB 13,10,"Enter string: $" 
    USER_INPUT_STRING     DB 80, 0, 80 DUP('$')
    BREAKLINE             DB 13, 10, "$"

.CODE
main PROC
    MOV AX, @DATA
    MOV DS, AX
    MOV ES, AX

    LEA DX,INPUT_STRING
    MOV AH, 09H
    INT 21H

    LEA DX, USER_INPUT_STRING
    MOV AH, 0AH
    INT 21H

    LEA DX, BREAKLINE
    MOV AH, 09H
    INT 21H

    CALL swap 
    CALL output
    CALL swap
    CALL capital
    CALL output


    MOV AX, 4C00H
    INT 21H
main ENDP

swap PROC
    MOV AH, USER_INPUT_STRING + 2             ;Swap letters
    MOV BL, USER_INPUT_STRING + 1
    MOV BH, 0
    MOV AL, USER_INPUT_STRING + 2 + BX - 1
    MOV USER_INPUT_STRING + 2, AL
    MOV USER_INPUT_STRING + 2 + BX - 1, AH
    RET
swap ENDP 

capital PROC
    SUB USER_INPUT_STRING + 2, 32       ;Capitalize
    MOV AH, 09H
    INT 21H  
capital ENDP  

output PROC 
    LEA DX, USER_INPUT_STRING + 2
    MOV AH, 09H
    INT 21H

    LEA DX, BREAKLINE
    MOV AH, 09H
    INT 21H   
    RET
output ENDP


END main

Solution

  • You need to remove the call to INT 21h in your capital function. Also you may want to have a RET too.

    capital PROC
        SUB USER_INPUT_STRING + 2, 32       ;Capitalize
        RET
    capital ENDP
    

    If you meant to have it continue to the output, then you can't call output again after calling capital.