News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Turning a low case sentence to Title Case

Started by historyb, April 21, 2018, 07:55:34 AM

Previous topic - Next topic

historyb

Hi all. I have a question about a project I am doing. I have tried countless things but all my program does is Capitalize the first word and nothing else. Yes this is an assignment and I do not want you all doing my homework. I just need a hint of what to do if any of you could. I forgot to say in my MakeTitle procedure I can only use one parameter.  Here is the code:

INCLUDE Irvine32.inc

MakeTitle PROTO, ;MakeTitle Prototype
str_01:PTR BYTE
PrintString PROTO, ;Prototype of setting for spli
String1:PTR BYTE

.data
str_array BYTE 50 DUP(?)
prompt BYTE "Please enter a text, no longer than 50 characters.  ", 0ah, 0dh, 0 ;Display message to user
msg BYTE "Your text has been changed successfully to ", 0ah, 0dh, 0;Display Message to User

.code
main PROC



mov edx, OFFSET prompt
call WriteString

mov edx, OFFSET str_array
mov ecx, SIZEOF str_array
call ReadString

INVOKE MakeTitle, ADDR str_array

INVOKE PrintString, ADDR str_array

main ENDP

;---------------------------------------------------------------
MakeTitle PROC uses eax ecx esi,
str_01:PTR byte
;
; finds next small capp
;
; Recieves: needs to take the string from the user and find
;           the small capp and make it Large Capp
;
; Returns: the string in TitleCase
;   
;---------------------------------------------------------------

mov eax, 0
mov esi, str_01
mov ecx, 50

mov al, [esi]

cmp al, 97
jl Testloop
mov al, [esi]
sub al, 32
mov [esi], al



Testloop:


mov al, [esi]
cmp al, 32
je CharTest
add esi, TYPE str_01
loop Testloop
jmp done

CharTest:
add esi, TYPE str_01
dec ecx
mov al, [esi]
cmp al, 91
jl Testloop
mov al, [esi]
mov dl, al
sub dl, 33
mov al, dl
Call writedec
call CRLF
mov [esi], eax
jmp Testloop

done:
ret
MakeTitle ENDP

;-----------------------------------------------------------
PrintString PROC USES edx, String1:PTR BYTE

; Display 2 lines for the string
;
; Recives: The String from the user
;
; Returns: nothing
;-----------------------------------------------------------

mov edx, String1
call WriteString
call Crlf

ret
PrintString ENDP

END main

jj2007

What happens if al is 32, i.e. space?
mov al, [esi]
sub al, 32
mov [esi], al


You want to eliminate the lowercase bit. Hint: To do the opposite, i.e. force lowercase, you would use or al, 32.

Lonewolff

jj2007 - Ha! That's clever.  :icon_cool:

Shows they were thinking when they designed the ASCII standard.

aw27

You are almost there, it is a pity it does not work.


Irvine32.inc

MakeTitle PROTO, ;MakeTitle Prototype
str_01:PTR BYTE, count:dword
PrintString PROTO, ;Prototype of setting for spli
String1:PTR BYTE

.data
str_array BYTE 51 DUP(0)
prompt BYTE "Please enter a text, no longer than 50 characters.  ", 0ah, 0dh, 0 ;Display message to user
msg BYTE "Your text has been changed successfully to ", 0ah, 0dh, 0;Display Message to User

.code
main PROC
mov edx, OFFSET str_array
mov ecx, SIZEOF str_array
call ReadString
mov edx, eax
INVOKE MakeTitle, ADDR str_array, edx
INVOKE PrintString, ADDR str_array
ret
main endp

MakeTitle PROC str_01:PTR BYTE, count:dword
mov esi, str_01
mov edi, esi

mov ecx, count
newone:
lodsb
cmp al, 97
jae @F
inc edi
loopnz newone
jmp @exit
@@:
cmp al, 122
jbe @F
inc edi
loopnz newone
jmp @exit
@@:
sub al, 32
stosb
loopnz newone
@exit:
ret
MakeTitle endp

PrintString PROC String1:PTR BYTE
mov edx, String1
call WriteString
call Crlf
ret
PrintString endp

end main


Better you do different than this, all teachers know how to google and will find this!

historyb

#4
Quote from: jj2007 on April 21, 2018, 08:04:02 AM
What happens if al is 32, i.e. space?
mov al, [esi]
sub al, 32
mov [esi], al


You want to eliminate the lowercase bit. Hint: To do the opposite, i.e. force lowercase, you would use or al, 32.

Thank you. I want to make sure I understand you because I can be a bit dense without meaning to. So it should be:

mov al, [esi]
or al, 32
mov [esi], al


or doing this:

mov al, [esi]
sub al, 32
or al, 32
mov [esi], al

historyb

Quote from: aw27 on April 21, 2018, 08:48:37 PM
You are almost there, it is a pity it does not work.


Irvine32.inc

MakeTitle PROTO, ;MakeTitle Prototype
str_01:PTR BYTE, count:dword
PrintString PROTO, ;Prototype of setting for spli
String1:PTR BYTE

.data
str_array BYTE 51 DUP(0)
prompt BYTE "Please enter a text, no longer than 50 characters.  ", 0ah, 0dh, 0 ;Display message to user
msg BYTE "Your text has been changed successfully to ", 0ah, 0dh, 0;Display Message to User

.code
main PROC
mov edx, OFFSET str_array
mov ecx, SIZEOF str_array
call ReadString
mov edx, eax
INVOKE MakeTitle, ADDR str_array, edx
INVOKE PrintString, ADDR str_array
ret
main endp

MakeTitle PROC str_01:PTR BYTE, count:dword
mov esi, str_01
mov edi, esi

mov ecx, count
newone:
lodsb
cmp al, 97
jae @F
inc edi
loopnz newone
jmp @exit
@@:
cmp al, 122
jbe @F
inc edi
loopnz newone
jmp @exit
@@:
sub al, 32
stosb
loopnz newone
@exit:
ret
MakeTitle endp

PrintString PROC String1:PTR BYTE
mov edx, String1
call WriteString
call Crlf
ret
PrintString endp

end main


Better you do different than this, all teachers know how to google and will find this!

Thank you this does help. Now I just will need to make the string Title Case but that should not be to hard now :)

jj2007

Quote from: historyb on April 22, 2018, 06:51:24 AMI can be a bit dense without meaning to. So it should be:

mov al, [esi]
or al, 32
mov [esi], al


or doing this:

mov al, [esi]
sub al, 32
or al, 32
mov [esi], al

No. Read my post, it says "to do the opposite, ...". Use your brain, and check the and instruction.

historyb

Quote from: jj2007 on April 22, 2018, 12:06:22 PM
Quote from: historyb on April 22, 2018, 06:51:24 AMI can be a bit dense without meaning to. So it should be:

mov al, [esi]
or al, 32
mov [esi], al


or doing this:

mov al, [esi]
sub al, 32
or al, 32
mov [esi], al

No. Read my post, it says "to do the opposite, ...". Use your brain, and check the and instruction.

okay, I am sorry I got it wrong

historyb

I want to thank everyone for their help   :t

zedd151

Quote from: historyb on May 01, 2018, 09:06:46 AM
I want to thank everyone for their help   :t
Does that mean that you got a good grade?