Author Topic: Turning a low case sentence to Title Case  (Read 809 times)

historyb

  • Regular Member
  • *
  • Posts: 5
Turning a low case sentence to Title Case
« on: April 21, 2018, 07:55:34 AM »
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:

Code: [Select]
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

  • Member
  • *****
  • Posts: 8773
  • Assembler is fun ;-)
    • MasmBasic
Re: Turning a low case sentence to Title Case
« Reply #1 on: April 21, 2018, 08:04:02 AM »
What happens if al is 32, i.e. space?
Code: [Select]
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.

Ascended

  • Member
  • ***
  • Posts: 331
Re: Turning a low case sentence to Title Case
« Reply #2 on: April 21, 2018, 09:23:27 AM »
jj2007 - Ha! That's clever.  :icon_cool:

Shows they were thinking when they designed the ASCII standard.

AW

  • Member
  • *****
  • Posts: 1496
  • Let's Make ASM Great Again!
Re: Turning a low case sentence to Title Case
« Reply #3 on: April 21, 2018, 08:48:37 PM »
You are almost there, it is a pity it does not work.

Code: [Select]
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

  • Regular Member
  • *
  • Posts: 5
Re: Turning a low case sentence to Title Case
« Reply #4 on: April 22, 2018, 06:51:24 AM »
What happens if al is 32, i.e. space?
Code: [Select]
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:

Code: [Select]
mov al, [esi]
or al, 32
mov [esi], al

or doing this:

Code: [Select]
mov al, [esi]
sub al, 32
or al, 32
mov [esi], al
« Last Edit: April 22, 2018, 11:02:53 AM by historyb »

historyb

  • Regular Member
  • *
  • Posts: 5
Re: Turning a low case sentence to Title Case
« Reply #5 on: April 22, 2018, 11:06:52 AM »
You are almost there, it is a pity it does not work.

Code: [Select]
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

  • Member
  • *****
  • Posts: 8773
  • Assembler is fun ;-)
    • MasmBasic
Re: Turning a low case sentence to Title Case
« Reply #6 on: April 22, 2018, 12:06:22 PM »
I can be a bit dense without meaning to. So it should be:

Code: [Select]
mov al, [esi]
or al, 32
mov [esi], al

or doing this:

Code: [Select]
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

  • Regular Member
  • *
  • Posts: 5
Re: Turning a low case sentence to Title Case
« Reply #7 on: April 22, 2018, 12:47:33 PM »
I can be a bit dense without meaning to. So it should be:

Code: [Select]
mov al, [esi]
or al, 32
mov [esi], al

or doing this:

Code: [Select]
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

  • Regular Member
  • *
  • Posts: 5
Re: Turning a low case sentence to Title Case
« Reply #8 on: May 01, 2018, 09:06:46 AM »
I want to thank everyone for their help   :t

zedd151

  • Member
  • ****
  • Posts: 850
Re: Turning a low case sentence to Title Case
« Reply #9 on: May 01, 2018, 10:59:24 AM »
I want to thank everyone for their help   :t
Does that mean that you got a good grade?
I'm not always the sharpest knife in the drawer, but I have my moments.  :P