Howdy, Stranger!

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


x86 NASM lowercase to uppercase !

Hi....i've been trying for days to complete a program that asks for a word input and prints it out in capitals.I searched in the forums but i only found TASM assembly...i need NASM...

Here is the program,i've managed to make it print out 1-the first- character (e.g. if i write "hello" it will print out "h"...i need it to print out "HELLO"):

; Objective: To print the capital equivalent of the entered character(s).
; Input: Requests the character(s) from keyboard.
; Output: Prints the ASCII character of the input in capital letters.

%include ""
segment .data
char_prompt db "Please input character(s): ",0
out_msg1 db "The equivalent of '",0
out_msg2 db "' in capital letter(s) is ",0

segment .text
global _asm_main
enter 0,0

mov EAX, char_prompt ;EAX=please input characters %
call print_string ;print char_prompt
call read_char ;read character fro user input
mov EBX, EAX ;copy EAX to EBX
call print_nl ;print new line

mov EAX, out_msg1
call print_string
mov EAX, EBX
call print_char
mov EAX, out_msg2
call print_string
mov EAX, EBX
cmp AL, 'a' ;
jl not_lowercase ; if lower than "a" jump to not_lowercase
cmp AL, 'z' ;
jg not_lowercase ; if greater than "z" jump to not_lowercase
add AL, 'A' - 'a' ; convert to uppercase
call print_char
sub AL, 20
loop process_char

mov EAX, 0

Hope it's not too much I'm asking...thanks in advance.


  • BitdogBitdog Member Posts: 528

    is a beginners assembly help environment.
    I'm loosing my webpage so it's yer last chance before 3-1-2010
    But it unzips to a directory w/subdirectories.
    In c:
    asminc16 dir you'll find tolower.mac & toupper.mac or .inc files which just simply toggle on or off bit 5 which is the difference between upper case alph & lower case alph.
    You don't even have to check if your AL value is >a & <z ?

    Fasm code here, it's real close to Nasm
    and AL,11011111b ;;= 223d = 0DFh, AND 2UPPER clears bit 5
    or AL,00100000b ;;= 32d = 20h, OR 2LOWER case sets bit 5

    Fasm is my personal assembler choice.

    Any there's a bunch of stuff in there you might find interesting.
    You can get command line input from CS:82h
    80h is the ARGC count, 82h is the first ARGV CMNDline .COM input.

    PS. double check my work, it's been a long time since I assembled.
  • 3y3ty3y3ty Member Posts: 15
    check if ASCII letter:
    cmp al, 'A'
    jb notletter
    cmp al, 'Z'
    ja checklower
    jmp is_letter
    cmp al, 'a'
    jb notletter
    cmp al, 'z'
    ja notletter
    jmp is_letter

    Then check bit 5
    TEST AL, 20h
    JZ UpperCase
    JNZ LowerCase

    XOR AL, 20h ; Turn to UpperCase

    To invert the case of any letter
    simply XOR the ASCII value by 32

Sign In or Register to comment.