Compress string lowercase for uppercase in Assembly

0

I made this code that reads a sentence and determines whether the first letter is uppercase or not, now I have to scan the whole sentence by changing where it is lowercase to uppercase, I'm having trouble with how to do this.

segment .data
msn db "Entre com uma frase:",sl
tam equ $-msn

msn1 db "Sua frase  comeca com  letra maiuscula:", sl
tam1 equ $-msn1

msn2 db "Sua frase nao comeca com  letra maiuscula:",sl
tam2 equ $-msn2

msn3 db " ",sl
tam3 equ $-msn3

sl equ 10
segment .bss
buf resb 100
buf2 resb 2


segment .text
global main
main:

     ;exibe string
      mov edx,tam    ;tamanho
      mov ecx,msn   ;ponteiro
      call print_str


     ;ler strim
      mov edx,100     ;tamanho da string
      mov ecx,buf    ;destino
      mov ebx, 0     ;Teclado
      mov eax, 3     ;read 
      int 0x80

      mov al,[buf +0]
      mov [buf2],al

      cmp byte[buf2,0],65
      jl minusculo 
      cmp byte[buf2,0],90
      jg minusculo 

      mov edx,tam1
      mov ecx, msn1  
      call print_str

      jmp fim


minusculo:

      mov edx,tam2
      mov ecx, msn2    
      call print_str

fim:      
      mov edx,tam3
      mov ecx,msn3
      call print_str


; ----------------- AREA DOS PROCEDIMENTOS ------------------

print_str:
    mov ebx, 1          ; Descritor (monitor = 1)
    mov eax, 4          ; Servico (print)
    int 0x80            ; Executa (exibe)
    ret             ; Devolve ao chamador
    
asked by anonymous 11.04.2018 / 21:28

1 answer

0

The difference between uppercase and lowercase in the ASCII table (for non-accented letters) is only the 6th bit.

To convert from lowercase to uppercase, simply reset bit 6 or make a logical AND with DFH = 1101 1111 or subtract 20H.

61H = 0110 0001 -> a

41H = 0100 0001 -> A

...

7AH = 0111 1010 -> z

5AH = 0101 1010 -> Z

To convert from uppercase to lowercase, simply set bit 6 or make a logical OR with 20H = 0010 0000 or even add 20H.

41H = 0100 0001 - A

61H = 0110 0001 - a

...

5AH = 0101 1010 -> Z

7AH = 0111 1010 -> z

This is valid only in the intervals from 41H to 5AH and 61H to 7AH.

Note also that if you use AND in the uppercase letter, it will remain uppercase, the same as for the OR: the lower case letter will remain lowercase.

For the program in question, read each bit of the string, compare the range, perform a logical AND with DFh, and print or save the character.

    
27.04.2018 / 03:42