User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Assembly section within the Software Development category of DaniWeb, a massive community of 401,739 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,224 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 9223 | Replies: 1
Reply
Join Date: Mar 2006
Posts: 1
Reputation: yep2678 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
yep2678 yep2678 is offline Offline
Newbie Poster

Help copy string and convert to upper case

  #1  
Mar 28th, 2006
This is what I have and think it is correct but the result shows up as all spaces... Im lost... Any help would be great. Thanks

0:000> ******************** process_strings.dbg
0:000> da message
*** WARNING: Unable to verify checksum for process_strings.exe
00404000 "You can't always get what you wa"
00404020 "nt"
0:000> da result
00404023 " "
00404043 " "
0:000> q
quit:

Code I have

TITLE process_strings
.586
.MODEL flat,stdcall
ExitProcess PROTO, ExitCodeWORD

.data
message BYTE "you cant always get what you want",0
result BYTE SIZEOF message DUP("?"),0

.code
public fini
loop4 PROC

;----------Copy the string message to result
mov ebx,0
mov ecx,LENGTHOF message
next_char: mov al,message[ebx]
mov result[ebx],al
add al,32h
inc ebx
loop next_char

fini:: push 0
call ExitProcess
loop4 ENDP
END loop4
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Posts: 6,061
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 419
Super Moderator
Narue's Avatar
Narue Narue is online now Online
Expert Meanie

Re: copy string and convert to upper case

  #2  
Mar 28th, 2006
next_char: mov al,message[ebx]
mov result[ebx],al
add al,32h
Watch your order of operations. You save the character to al, then copy al to the result string, *then* modify al. Also, if you're converting an ASCII letter to upper case, you need to subtract because the upper case letters are less in value than the lower case letters. Also, it's 32 decimal, not 32 hexadecimal.
mov al,message[ebx]
sub al,32
mov result[ebx],al
A cooler way to convert ASCII is to clear the 5th bit, which is what the subtraction does, but you can more directly show your intentions with AND:
mov al,message[ebx]
and al,0DFh
mov result[ebx],al
But that's also not quite right because not all of the characters in your string are in the valid range of 'a' to 'z'. If you apply any unconditional transformation on those characters, you'll get weird results. Most notably, a space becomes a null character because 32 is 00100000b, and you're effectively clearing the only set bit. You need to add some sanity checks:
next_char:
	mov	al,message[ebx]
	cmp	al,'a'
	jb	no_change
	cmp	al,'z'
	ja	no_change
	and	al,0DFh
no_change:
	mov	result[ebx],al
	inc	ebx
	loop	next_char
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Assembly Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Assembly Forum

All times are GMT -4. The time now is 9:36 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC