Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

converts uppercase user input into lowercase

hi, i was reading through my assembly book and i wonder how would i write an assembly language program that accepts uppercase user input and converts it to lowercase.

Comments

  • anthrax11anthrax11 Member Posts: 511
    : hi, i was reading through my assembly book and i wonder how would i write an assembly language program that accepts uppercase user input and converts it to lowercase.
    :

    That's easy, all you need to do is OR the input with 32.

    The idea is to add 32 to uppercase chars and leave lowercase as they are:
    "A" = 65 (97-32)
    "a" = 97 (65+32)
    The only difference between uppercase and lowercase is that for lowercase, the fifth bit is always set

    [code]
    lcase segment
    assume cs:lcase,ds:lcase,es:lcase
    org 0100h
    start:

    mov ah,0ah
    mov dx,offset bytestoread
    int 21h ;Get input

    xor bx,bx ;Bx will be the counter
    nextchr:
    or [inpbuffer+bx],32 ;OR the ASCII char with 32
    inc bx ;Next
    cmp bl,bytesread ;Are we done?...
    jb nextchr ;...Nope, OR the next one

    mov bl,bytesread
    xor bh,bh
    mov [bx+inpbuffer+1],"$" ;Add the symbol for printing it out
    mov ah,9 ;...Yes, print it out
    mov dx,offset inpbuffer
    int 21h

    ret

    bytestoread db 64 ;Maximum number of bytes to read
    bytesread db ? ;Bytes read
    inpbuffer db 64 dup(?) ;The buffer for the input

    lcase ends
    end start
    [/code]
    And if you want to get upper case input, just AND it with 223(255-32). Like this:
    [code]and [inpbuffer+bx],223[/code]

    Also, you should make sure that you dont OR anything other than letters because otherwise it will mess up the input. For example, if you OR "!" with 32 you get a smiley, or for "#" you get a heart, Dont OR any numbers too. Hope you understood something:-)
  • indianjindianj Member Posts: 20
    thanks for your help.
Sign In or Register to comment.