convert character (help!)
I want to convert the first of character each sentence to uppercase.For example i put in message1 then i change it.But i fail to run this program, so please help me recheck this program which is written in the TASM. Do you have any suggestion web sites about the TASM, assembly language, example, because i'm a beginner. Thank you..
;convert.asm
.model small
.stack 200h
.data
message1 Db 'i am a boy. you are a girl.'
.code
start:
mov ax, seg message1
mov ds, ax
cld
mov si, offset message1
call To_Uppercase
mov ah, 9
mov dx, offset message1
int 21h
To_Uppercase:
cmp byte ptr [si], '.'
je Done
mov [si-1], al
jmp To_Uppercase
Done:
lodsb
and al, 11011111b
Last:
mov ax,4c00h
int 21h
End start
Re: convert character (help!)
I somehow modified your code. I have not tested it (or not even try compiling it) because I dont have compiler at home but I think (I hope) it would be ok
Code:
.model small
.stack 200h
.data
last_char_processed Db '.'
message1 Db 'i am a boy. you are a girl.$'
.code
start:
mov ax, seg message1
mov ds, ax
cld
mov si, offset message1
process_next_char:
lodsb
; if the terminator is found then go printing the string
cmp al, '$'
je print_now
; if it is a space char, proceed to next character
cmp al, ' '
je process_next_char
; on all other characters, check first if the last processed is '.'
; if not goto default_char_processing
cmp byte ptr [last_char_processed], '.'
jne default_char_processing
; if less than 'a' (in the ascii table), dont make it uppercase
cmp al, 'a'
jb default_char_processing
; if more than 'z' (in the ascii table), dont make it uppercase
cmp al, 'z'
ja default_char_processing
; we meet all the requirements here and we now make it uppercase
and byte ptr [si - 1], 11011111b
default_char_processing:
; this will save the las character processed into our flag.
; We need this so that we can check if we will make the next
; character uppercase or not. After saving, go to next char.
mov last_char_processed, al
jmp process_next_char
print_now:
; print the string now
mov ah, 9
mov dx, offset message1
int 21h
Last:
mov ax,4c00h
int 21h
End start
Hope it will help you
Re: convert character (help!)
I can't understand why here put this:
process_next_char:
lodsb
Why don't we put after the default_char_processing?
Re: convert character (help!)
I can't understand why here put this:
lodsb in the process_next_char
Why don't we put after the default_char_processing?
I can't understand what is the purpose for this procedure?
default_char_processing:
mov last_char_processed, al
jmp process_next_char
Sorry because i just a new learner, so have a lot of thing can't understand. SO please help me.
Re: convert character (help!)
I placed the lodsb in the process_next_char because as the program executes, it has to load the character first before evaluating it. LODSB places the character FROM MEMORY TO REGISTER AL. If we placed it in default_char_processing, then we would be dealing with UNPREDICTED AL value as we compare it the first time since AX is assigned with the segment of message1. In simple words, you have to read it first before we can check it.
What default default_char_processing does is only to save whatever the last character processed and then go back to read another character (jmp process_next_char). We have to save whatever the last character processed so if we go to the next character, we have record on what was the character before it. If it is a period (".") or not. Note that we dont record spaces in the last_char_processed because sentences generally have spaces after the period. That is why we check first if it is a space (cmp al, ' ') before further processing.
Hope it will clarify your concerns
Re: convert character (help!)
Why don't we consider the space behind the '.'? Because as in the example of websites" http://yahoo.com.", it is not suitable to convert the com to Com. And how about if after the '.' is the enter, how to cmp it and convert the next character to uppercase?
Re: convert character (help!)
I thought it would be just simple sentences, I'm sorry for that. Here are the modification I made to accomodate the web addresses format and also the cr/lf characters.
Code:
.DATA
last_char_processed DB '.'
is_token_found DB 1
message1 DB 'i am a boy. you are a girl.', 0dh, 0ah
DB 'go to http://yahoo.com.$'
.code
start:
mov ax, seg message1
mov ds, ax
cld
mov si, offset message1
process_next_char:
lodsb
; if the terminator is found then go printing the string
cmp al, '$'
je print_now
; if it is a token (space/cr/lf), proceed to process_token
cmp al, ' '
je process_token
cmp al, 0dh
je process_token
cmp al, 0ah
je process_token
; if it is a period, proceed to process_period
cmp al, '.'
je process_period
; on all other characters, check first if the last processed is '.'
; if not goto default_char_processing
cmp Byte Ptr [last_char_processed], '.'
jne default_char_processing
; check also if the last processed is a token (period / cr / lf)
; if not goto default_char_processing
cmp Byte Ptr [is_token_found], 1
jne default_char_processing
; if less than 'a' (in the ascii table), dont make it uppercase
cmp al, 'a'
jb default_char_processing
; if more than 'z' (in the ascii table), dont make it uppercase
cmp al, 'z'
ja default_char_processing
; we meet all the requirements here and we now make it uppercase
and byte ptr [si - 1], 11011111b
default_char_processing:
; this will save the las character processed into our flag.
; We need this so that we can check if we will make the next
; character uppercase or not. After saving, go to next char.
mov last_char_processed, al
jmp process_next_char
process_period:
; reset our token flag
mov Byte Ptr [is_token_found], 0
jmp default_char_processing
process_token:
; before we set the token flag, check first if the last character is '.'
cmp Byte Ptr [last_char_processed], '.'
jne process_next_char
; and set it only if it is in deed '.'
mov Byte Ptr [is_token_found], 1
jmp process_next_char
print_now:
; print the string now
mov ah, 9
mov dx, offset message1
int 21h
Last:
mov ax,4c00h
int 21h
End start
Re: convert character (help!)
Thank you very much for your program!! And it can works properly.But may be this program is quite hard for me as a new learner, so i think i need more time to understand it. I would like to ask whether do you online every night? If yes, if i have problem, may i ask you through this forum? I really feel thankful to you.Thank you!
Re: convert character (help!)
You're very much welcome. You'll also learn all these in time. :thumb:
I'm online very often and this forum is one of the forums I visit most in this site. You can just post and I'm always be willing to help.
Good luck.
Re: convert character (help!)
Thank you for your program, because i can understand that program, although need more time to understand it.Actually, now i am learning Microprocessors chapter which mainly about the string. And i found that it is really interesting. I would like to ask whether, can you give me any suggestions about the websites, which have example TASM program or program which related with string? I would like to know more about the string..Thank you.