Assembly language

Converting from Lowercase to Uppercase

Page 1 of 1

6 Replies - 6932 Views - Last Post: 07 October 2007 - 12:08 PM Rate Topic: -----

#1 tinytoh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-April 07

Assembly language

Post icon  Posted 06 October 2007 - 01:02 PM

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.

.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

Is This A Good Question/Topic? 0
  • +

Replies To: Assembly language

#2 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 205
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: Assembly language

Posted 06 October 2007 - 04:57 PM

what is the error you are recieving?
Was This Post Helpful? 0
  • +
  • -

#3 tinytoh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-April 07

Re: Assembly language

Posted 06 October 2007 - 07:21 PM

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
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5248
  • View blog
  • Posts: 27,071
  • Joined: 10-May 07

Re: Assembly language

Posted 06 October 2007 - 07:36 PM

Are you getting the error when you run the program or when you try to assemble it?
Was This Post Helpful? 0
  • +
  • -

#5 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: Assembly language

Posted 06 October 2007 - 11:18 PM

You could also XOR the character with 32. It's much safer to use in this case instead of SUB.
;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:
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:
call	getch	 ;reads the lowercase letter or % symbol
mov	cl,ERR
cmp	cl,al


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.
Was This Post Helpful? 0
  • +
  • -

#6 tinytoh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-April 07

Re: Assembly language

Posted 07 October 2007 - 06:48 AM

Well, I edited my code to contain returns and switched the order of GetCh, but still no luck :v: .

I have attached the new code as well as the errors I received from MASM.
; 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:

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.. :D
Was This Post Helpful? 0
  • +
  • -

#7 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: Assembly language

Posted 07 October 2007 - 12:08 PM

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:
alpha PROC
alpha1:
;code
;...
;...
;...
alpha endp
end alpha1

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1