Welcome to Dream.In.Code
Become an Expert!

Join 149,596 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,878 people online right now. Registration is fast and FREE... Join Now!




Assembly language

 
Reply to this topicStart new topic

Assembly language, Converting from Lowercase to Uppercase

tinytoh
6 Oct, 2007 - 12:02 PM
Post #1

New D.I.C Head
*

Joined: 9 Apr, 2007
Posts: 11


My Contributions
I am trying to implement a program that will allow a user to enter a lowercase letter and then out put it as an uppercase letter. You can assume that only lowercase letters or % will be entered. This repeats until the % sign is entered.

I am getting an error, but I am not sure what it is due to. The following is my code.

CODE

.MODEL SMALL
.586; Allows Pentium instructions
.STACK 100h
        CR     EQU     10d
        LF     EQU     13d
        
.DATA
        ERR    DB    25h
        message    DB    'Begin entering lowercase alphabet characters. When you are finished, type %.',CR, LF, '$'

.CODE
go        PROC
        mov     ax, @data
        mov     ds, ax
        mov     dx, OFFSET message;displays the string of characters stored in "message"
        mov     ah, 9h
        int     21h
convert:
        mov    cl,ERR
        call    getch        ;reads the lowercase letter or % symbol
        cmp    cl,al
        je    end
        mov    bl,al
        sub    bl,32d        ;subtract 32 convert from lowercase to uppercase
        call    putch        ;displays the uppercase version of the lowercase value entered
        jmp    convert
getch:
        mov     ah, 01h     ;Display DOS func code
        int     21h         ;Call DOS    

putch:
        mov     dl, bl        ;displays the character
        mov     ah, 2h
        int     21h
end:
        mov    al,0        ;Exits the program - _Exit equivelant
        mov    ah,4ch
        int    21h    
go        ENDP

        END    go        ; Tells where to start execution


Any help would be greatly appreciated.

Thanks,

Eric
User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Assembly Language
6 Oct, 2007 - 03:57 PM
Post #2

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 4,101



Thanked: 25 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
what is the error you are recieving?
User is offlineProfile CardPM
+Quote Post

tinytoh
RE: Assembly Language
6 Oct, 2007 - 06:21 PM
Post #3

New D.I.C Head
*

Joined: 9 Apr, 2007
Posts: 11


My Contributions
I am using MASM as my compiler and it gives me a fatal error. It says that it cannot run the program...Maybe I have something in the wrong register?

Is the way I stored the % sign correct (the value stored in ERR)?

I haven't been able to determine where I went wrong.

Thanks for the help.

Eric
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Assembly Language
6 Oct, 2007 - 06:36 PM
Post #4

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 7,133



Thanked: 76 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
Are you getting the error when you run the program or when you try to assemble it?
User is online!Profile CardPM
+Quote Post

born2c0de
RE: Assembly Language
6 Oct, 2007 - 10:18 PM
Post #5

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 4,026



Thanked: 38 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
You could also XOR the character with 32. It's much safer to use in this case instead of SUB.
CODE
;Assuming the the character is stored in AL
xor     AL ,  20h

This can also convert uppercase into lowercase.

Now, take a look at this fragment:
CODE
mov    cl,ERR
call    getch     ;reads the lowercase letter or % symbol
cmp    cl,al

Although this may not create a problem in this case (since you have defined the getch code yourself), there is a chance that the called function is modifying the CL register without the PUSH CX/POP CX instruction pair.
Hence a wiser step that you could take would be:
CODE
call    getch     ;reads the lowercase letter or % symbol
mov    cl,ERR
cmp    cl,al


CODE
call getch
...
...
...

getch:
        mov     ah, 01h;Display DOS func code
        int     21h;Call DOS    

putch:
        mov     dl, bl     ;displays the character
        mov     ah, 2h
        int     21h
end:
        mov    al,0     ;Exits the program - _Exit equivelant
        mov    ah,4ch
        int    21h

Since you're using the CALL instruction, control won't be passed onto the next statement (after call getch) until a RETN instruction is encountered. This could be the cause of your crash.
Either use JMP getch along with GOTOs planted at the end of getch and putch blocks, or place a RETN instruction at the end of getch/putch.
User is online!Profile CardPM
+Quote Post

tinytoh
RE: Assembly Language
7 Oct, 2007 - 05:48 AM
Post #6

New D.I.C Head
*

Joined: 9 Apr, 2007
Posts: 11


My Contributions
Well, I edited my code to contain returns and switched the order of GetCh, but still no luck icon_down.gif .

I have attached the new code as well as the errors I received from MASM.
CODE

; Filename: Project 1
; Program Name: “Alphabet Echoes”
; Author: Eric Taylor
; Class: EECS 2100 - Comp. Org. and Asssembly
; Creation Date: 9-30-07
; Revisions:
; Date: Modified by:
; Program Description: Alphabet Echo

.MODEL SMALL
.586; Allows Pentium instructions
.STACK 100h
        CR     EQU     10d
        LF     EQU     13d
        
.DATA
        ERR    DB    25h
        message    DB    'Begin entering lowercase alphabet characters. When you are finished, type %.',CR, LF, '$'

.CODE

alpha        PROC
        mov     ax, @data
        mov     ds, ax
        mov     dx, OFFSET message;displays the string of characters stored in "message"
        mov     ah, 9h
        int     21h
        jmp    convert
convert:
        call    getch        ;reads the lowercase letter or % symbol
        mov    cl,ERR
        cmp    cl,al
        je    end
        mov    bl,al
        sub    bl,32d        ;subtract 32 convert from lowercase to uppercase
        call    putch        ;displays the uppercase version of the lowercase value entered
        jmp    convert
getch:
        mov     ah, 01h     ;Display DOS func code
        int     21h         ;Call DOS
        ret    

putch:
        mov     dl, bl        ;displays the character
        mov     ah, 2h
        int     21h
        ret
end:
        mov    al,0        ;Exits the program - _Exit equivelant
        mov    ah,4ch
        int    21h

alpha        ENDP

        END    alpha        ; Tells where to start execution


and my errors are as follows:

CODE

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\ETaylor>cd C:\masm

C:\masm>ml project1.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: project1.asm
project1.asm(31) : error A2008: syntax error : end
project1.asm(50) : fatal error A1010: unmatched block nesting : alpha

C:\masm>



Thanks for the help eveyone.. biggrin.gif
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Assembly Language
7 Oct, 2007 - 11:08 AM
Post #7

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 4,026



Thanked: 38 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
There's nothing wrong with the code.
You haven't closed the procedure blocks properly.

Try removing the END alpha statement.
That is to be used only if you insert a label after a proc like this:
CODE

alpha PROC
alpha1:
;code
;...
;...
;...
alpha endp
end alpha1


User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 11:27PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month