0

I'm trying to write a program that reads 3 strings from the keyboard and then display 2 strings in lowercase and the last one in uppercase. Here's what I've got till now: I can read the string, but then it converts everything to uppercase. Is there anyway to convert only the last string? Thanks in advance

.MODEL SMALL
.DATA
    MSG  DB  0DH,0AH, 'ENTER A STRING: $'
    MSG2 DB  0DH,0AH, ' YOUR STRING IS  :-----> :  $'
    STR1 DB  255 DUP(?)
.CODE
BEGIN:

    MOV AX,@DATA
    MOV DS,AX

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

    LEA SI,STR1 
    MOV AH,01H

READ:
    INT 21H 
    ;MOV BL,AL

    CMP AL,0DH
    JE  DISPLAY

    SUB AL,20H
    MOV [SI],AL
    INC SI

    ;CMP BL,0DH
    JMP READ

DISPLAY:

    MOV AL,'$'  ;caracter '$'
    MOV [SI],AL ;

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


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

    ; MOV AH,4CH
    ; INT 21H

.EXIT
END BEGIN

I'm using TASM.

  • 1
    *Is there anyway to convert only the last string?* Yes, of course there is. One way would be to keep track of the position at the end of the first two strings, so you can loop over just the last string once you're done reading input. – Peter Cordes Oct 31 '16 at 01:29
  • 2
    Sorry, but you trigger my sarcasm hard... like "no, all string in computers have to be uppercase now". You have basically answer in your own question. Just don't convert the first two strings, and then only third one will get converted. Try to think about it as an calculation, break the problem into some formula, counters, numbers manipulation... even strings are just stream of consecutive byte values (0-255) in ASCII encoding. So if you want to do something only with some particular string, define first how you decide when string starts/stops (per space?). Count them. Execute uppercase on 3rd – Ped7g Oct 31 '16 at 02:01
  • 2
    And `sub al,20h` is a bit lame way to "uppercase", what will it do to already uppercase letter, like `'A'`? Check the `AND` rather, how it works, and then look at the ASCII table ... it was specifically designed for this task, that's the reason why `'a'` is `'A' OR 0x20`, and not `'Z'+1`. – Ped7g Oct 31 '16 at 02:05

1 Answers1

0

Thank you everyone for your comments. I was able to solve it this way:

.MODEL SMALL
.STACK 100h
.DATA
    Mensagem1  DB  "Meu Prompt>>",'$',13,10
    first DB  80 DUP (?)
.CODE
    MOV AX, @DATA
    MOV DS, AX
    LEA DX, Mensagem1
    MOV AH, 9
    INT 21H
    LEA SI, first   
READ:
    MOV AH, 01H
    INT 21H
    CMP AL, 13
    JE  DONE
    OR AL, 20H
    MOV [SI], AL
    INC SI
    CMP AL, 20H
    JE READ2
    JMP READ
READ2:
    INT 21H
    CMP AL, 13
    JE  DONE
    OR AL, 20H
    MOV [SI], AL
    INC SI
    CMP AL, 20H
    JE READ3
    JMP READ2
READ3:
    INT 21H
    CMP AL, 13
    JE  DONE
    XOR AL, 20H
    MOV [SI], AL
    INC SI
    JMP READ3
DONE:
    MOV AL, '$'
    MOV [SI], AL
    LEA DX, Mensagem1
    MOV AH, 9
    INT 21H
    LEA DX, first
    MOV AH, 9
    INT 21H
    MOV AH,4CH
    INT 21H
END
  • `XOR AL, 20H` flips the case, which is different from always making it uppercase. Also, you need some conditions if you want to make sure you don't change non-alphabetic characters (e.g. `'-'` or `'7'`). There are several detailed answers on http://stackoverflow.com/questions/35932273/how-to-access-a-char-array-and-change-lower-case-letters-to-upper-case-and-vice. – Peter Cordes Nov 02 '16 at 03:41