944,183 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 14167
  • Assembly RSS
Mar 28th, 2006
0

copy string and convert to upper case

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yep2678 is offline Offline
1 posts
since Mar 2006
Mar 28th, 2006
0

Re: copy string and convert to upper case

Assembly Syntax (Toggle Plain Text)
  1. next_char: mov al,message[ebx]
  2. mov result[ebx],al
  3. 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.
Assembly Syntax (Toggle Plain Text)
  1. mov al,message[ebx]
  2. sub al,32
  3. 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:
Assembly Syntax (Toggle Plain Text)
  1. mov al,message[ebx]
  2. and al,0DFh
  3. 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:
Assembly Syntax (Toggle Plain Text)
  1. next_char:
  2. mov al,message[ebx]
  3. cmp al,'a'
  4. jb no_change
  5. cmp al,'z'
  6. ja no_change
  7. and al,0DFh
  8. no_change:
  9. mov result[ebx],al
  10. inc ebx
  11. loop next_char
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: is this code Right and why
Next Thread in Assembly Forum Timeline: Give a try....





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC