1 Replies - 789 Views - Last Post: 23 April 2018 - 12:16 PM

#1 charsan2   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-April 18

Trying to turn lower case sentence to title case

Posted 19 April 2018 - 11:18 AM

Hi everyone,

I am sorry to brother you all. I have a problem, I am tying to do a project that takes a lower case string that the user enters and changes it to Title case. Example - how are you to How Are You.

My problem is that the program changes the first letter and than does not change anything else and returns: How are you. I have changed everything even trying to figure out the math and I am stuck. I tried changing add esi, TYPE str_01 to inc esi and that did not work. I tried searching on google but could not find a lot but google did bring me here. Any help would be appreciated. I am using MASM in Visual Studio with the irvine library. 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
]

I hope I did everything correctly and thank you in advance

Is This A Good Question/Topic? 0
  • +

Replies To: Trying to turn lower case sentence to title case

#2 turboscrew   User is offline

  • D.I.C Lover
  • member icon

Reputation: 171
  • View blog
  • Posts: 1,107
  • Joined: 03-April 12

Re: Trying to turn lower case sentence to title case

Posted 23 April 2018 - 12:16 PM

I've mentioned it several times before, that I'm not very competent with x86 architecture, but...

On line 71, a byte is loaded, but on line 80 a double word (32 bits) is stored.
I guess the low case letter becomes replaced by a capital letter, and the next 3 characters are overwritten with zeroes.
With 2 and 3 letter words... you know...

Also, when you hit a blank, you skip the pointer advancing and count decrementation, and jump to the CharTest.
There you increment the pointer over the blank and decrement count by one.
Then you handle the next character and jump back to TestLoop and continue with the character you already handled.
You might want to increment the pointer and decrement the count before jumping back to TestLoop (between lines 80 and 81).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1