0

Hello so i am making a program where the user inputs a string and the output string should be in capital letters. But what i am getting is the same length of output as the input and all capitalized letters- but the letter is only "A". I don't know if the program can read the buffer or how to correct if it not, or something else is just wrong with my code. Please help

READ MACRO MSG
    MOV AH,0AH
    LEA DX,MSG
    INT 21H
ENDM

PRINT MACRO MSG
    MOV AH,09H
    LEA DX,MSG
    INT 21H
ENDM

DATA SEGMENT
    CR EQU 0DH
    LF EQU 0AH
    MSG1 DB "ENTER THE STRING IN LOWERCASE:$"
    MSG2 DB CR,LF,"THE UPPERCASE STRING IS :$"

BUFF DB 255
             DB 0
             DB 255 DUP ('$')
DATA ENDS

CODE SEGMENT
    ASSUME CS:CODE,DS:DATA
START:    
    MOV AX,DATA
    MOV DS,AX
    
    PRINT MSG1
    READ BUFF
    MOV SI,OFFSET BUFF+2
    MOV CL,BYTEPTR[SI-1]
    MOV CH,00H

LP1:MOV AH,[SI]
    MOV AL,61H
JB LP1
    CMP AL,7BH
    JNB LP1
    SUB AL,20H
    MOV [SI],AL

LP2:
    INC SI
    LOOP LP1
    PRINT MSG2
    PRINT BUFF+2
    MOV AH,4CH
    INT 21H
CODE ENDS
END START
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
takbudo
  • 25
  • 7
  • Did you single-step with a debugger to see if the input is getting read into memory, and then to see what values you're loading into registers as you loop through the string? – Peter Cordes Apr 19 '21 at 02:23
  • 1
    `JB LP1` looks broken; you haven't done anything to set FLAGS before the first time that runs, and if it's taken you'll create an infinite loop reloading the same byte over again. (Note that MOV does not set FLAGS). Perhaps you meant to `cmp` and jump to LP2 with that and the next branch? Oh, and you load [SI] into AH, but then `mov AL, 61H` (`'A'`), and the rest of the loop looks at AL, not AH. – Peter Cordes Apr 19 '21 at 02:25
  • Also related: [What is the idea behind ^= 32, that converts lowercase letters to upper and vice versa?](https://stackoverflow.com/a/54585515) / [double condition checking in assembly](https://stackoverflow.com/a/5197264) - you can uppercase and check for alphabetic at the same time, with only one compare. – Peter Cordes Apr 19 '21 at 02:29
  • @PeterCordes your comment actually worked! Thank you all for the info – takbudo Apr 20 '21 at 16:21

0 Answers0