Now i was given a task, which is read a data which was given in the program and convert it into uppercase! but i fail to do it. now i post example of the program and hopefully got kind people help me to check where is the problem.thanks....
EXAMPLE:
;convert.asm
.model small
.stack 200h
.data
message1 Db 'abCdEF ghO/"0()ijklwmohcoc'
.code
start:
mov ax, seg message1
mov ds, ax
mov di, offset message1
mov bl,[di]
mov bh,0
mov BYTE PTR [BX+di],'$'
add bx, 2
lowercase:
cmp byte ptr [bx], 'a'
jb character
cmp byte ptr [bx], 'z'
ja character
and byte ptr [bx], 11011111b
character:
inc bx
loop lowercase
mov dx, di
mov ah,09
int 21h
Last:
mov ax,4c00h
int 21h
End start
Comments
:
: EXAMPLE:
: ;convert.asm
: .model small
: .stack 200h
: .data
: message1 Db 'abCdEF ghO/"0()ijklwmohcoc'
:
: .code
: start:
: mov ax, seg message1
: mov ds, ax
:
: mov di, offset message1
: mov bl,[di] [red]whats all this for? Your index is di. What if you had a junk value in di[/red]
: mov bh,0
:
:
: mov BYTE PTR [BX+di],'$' [red]???[/red]
: add bx, 2
:
: lowercase:
: cmp byte ptr [bx], 'a'
: jb character [red]Not needed[/red]
: cmp byte ptr [bx], 'z'
: ja character
: and byte ptr [bx], 11011111b
:
: character:
: inc bx
: loop lowercase
: mov dx, di
: mov ah,09
: int 21h
:
: Last:
: mov ax,4c00h
: int 21h
: End start
:
[green]
Maybe
[code]
cld
mov si, offset mystring
To_Uppercase:
cmp byte [si], '$'
je Done
lodsb
and al, 11011111b
mov [ds:si-1], al
jmp To_Uppercase
Done:
ret
mystring db "abCdEF ghO/"0()ijklwmohcoc", '$'
[/code]
Here's a program that takes input from the keyboard that I made and converts to uppercase.
[code]
;NASM-IDE ASM Assistant Assembler Project File
BITS 16 ;Set code generation to 16 bit mode
ORG 0x0100 ;Set code start address to 0100h
;TO UPPERCASE USING DOS SERVICES, SIMPLER VERSION!
SEGMENT .text ;Main code segment
mov ax, 0003h
int 10h
mov ah, 9
mov dx, msg
int 21h
mov ah, 0ah
mov dx, buffer
int 21h
mov si, buffer+2
cld
call To_Uppercase
mov ah, 9
mov dx, crlf
int 21h
mov ah, 9
mov dx, toupper
int 21h
mov ah, 9
mov dx, buffer+2
int 21h
mov ah, 9
mov dx, crlf
int 21h
mov ah, 9
mov dx, anykey
int 21h
mov ah, 0
int 16h
mov ax, 4c00h
int 21h
To_Uppercase:
cmp byte [si], '$'
je Done
lodsb
and al, 11011111b
mov [ds:si-1], al
jmp To_Uppercase
Done:
ret
SEGMENT .data ;Initialised data segment
msg db "Please enter up to 16 characters to convert to uppercase: ",'$'
buffer db 17
db 0
times 17 db 0
db '$'
crlf db 10,13,10,13,'$'
toupper db "Conversion to uppercase: ",'$'
anykey db "Press any key to continue",'$'
SEGMENT .bss ;Uninitialised data segment
[/code]
:
[green]
Not without a little modification but the first code example I posted should work. You don't have to check for a letter to convert to uppercase or even lower case. All you have to do is clear bit 5.
[/green]
:
[green]
The 1st code portion is what you need. I just posted my example program as a reference. It's very easy to follow if you look at it.
[/green]
;convert.asm
.model small
.stack 200h
.data
message1 Db 'abCdEF ghO/"0()ijklwmohcoc'
.code
start:
mov ax, seg message1
mov ds, ax
cld
mov si, offset message1
To_Uppercase:
cmp byte [si], '$' "It says here argument needs type override"
je Done
lodsb
and al, 11011111b
mov [ds:si-1], al "it says ":" operator ignored"
jmp To_Uppercase
Done:
ret
Last:
mov ax,4c00h
int 21h
End start
EXAMPLE
;stg.asm
.model small
.stack 200h
.data
message1 DB 'Please type a string (up to 254 character) in upper case ? $'
string db 254,255 dup(0)
message2 db 10,13, 'The string in lower case $'
.code
start:
mov ax, seg message1
mov ds, ax
mov dx, offset message1
mov ah,09h
int 21h
mov dx,offset string
mov ah,0Ah
int 21h
mov dx, offset message2
mov ah,09h
int 21h
mov di, offset string
inc di
mov bl,[di]
mov bh,0
inc di
mov BYTE PTR [BX+di],'$'
add bx, 2
lowercase:
cmp byte ptr [bx], 'a'
jb character
cmp byte ptr [bx], 'z'
ja character
and byte ptr [bx], 11011111b
character:
inc bx
loop lowercase
mov dx, di
mov ah,09h
int 21h
mov ax,4c00h
int 21h
End start
Here is my succecful program which can convert the input typed by the user to uppercase, but now my new task is to convert the input which insert in front of the program to uppercase. I fail to modify from this program..Please help me...
;stg.asm
.model small
.stack 200h
.data
message1 DB 'Please type a string (up to 254 character) in upper case ? $'
string db 254,255 dup(0)
message2 db 10,13, 'The string in lower case $'
.code
start:
mov ax, seg message1
mov ds, ax
mov dx, offset message1
mov ah,09h
int 21h
mov dx,offset string
mov ah,0Ah
int 21h
mov dx, offset message2
mov ah,09h
int 21h
mov di, offset string
inc di
mov bl,[di]
mov bh,0
inc di
mov BYTE PTR [BX+di],'$'
add bx, 2
lowercase:
cmp byte ptr [bx], 'a'
jb character
cmp byte ptr [bx], 'z'
ja character
and byte ptr [bx], 11011111b
character:
inc bx
loop lowercase
mov dx, di
mov ah,09h
int 21h
mov ax,4c00h
int 21h
End start
I'm not familiar with TASM syntax but try this.
[/green]
: I already try the program, but the program fail to run. SO can you help me to recheck.thanks..
:
:
:
: ;convert.asm
: .model small
: .stack 200h
: .data
[red] message1 Db "abCdEF ghO/"0()ijklwmohcoc", '$' [/red]
:
: .code
: start:
: mov ax, seg message1
: mov ds, ax
: cld
: mov si, offset message1
[red]
call To_Uppercase
mov ah, 9
mov dx, offset message1
int 21h
mov ah,0
int 16h
: Last:
: mov ax,4c00h
: int 21h
: End start
[/red]
: To_Uppercase:
[red] cmp byte ptr [si], '$'[/red]
: je Done
: lodsb
: and al, 11011111b
[red] mov [si-1], al[/red]
: jmp To_Uppercase
:
: Done:
: ret
:
:
:
:
[green]
Look at the ASCII table for uppercase letters. You will see that bit 5 is cleared when you convert the values to binary. To convert to lowercase then you would set bit 5.
Example
[code]
'A' = 0100 0001
'a' = 0110 0001
bit 5 is off in regards to uppercase while in lowercase it is on.
[/code]
[/green]
EXAMPLE
;convert.asm
.model small
.stack 200h
.data
message1 Db "abCdEF ghO/"0()ijklwmohcoc", '$' "It says there extra characters on line"
.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
lodsb
and al, 11011111b
mov [si-1], al
jmp To_Uppercase
Done:
ret
mov ah,0
int 16h
Last:
mov ax,4c00h
int 21h
End start
:
: EXAMPLE
: ;convert.asm
: .model small
: .stack 200h
: .data
[red]message1 Db '1abCdEF ghO/"0()ijklwmohcoc$'[/red]
:
: .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
: lodsb
: and al, 11011111b
: mov [si-1], al
: jmp To_Uppercase
:
: Done:
: ret
: mov ah,0
: int 16h
:
:
:
: Last:
: mov ax,4c00h
: int 21h
: End start
:
:
:
Here EXAMPLE 1 is my successful program which convert the input from keyboard ti uppercase.My new task is to convert the input which insert in front of program. EXAMPLE2 is the program which i fail to run it. SO please help me check it..
EXAMPLE 1
;stg.asm
.model small
.stack 200h
.data
message1 DB 'Please type a string (up to 254 character) in upper case ? $'
string db 254,255 dup(0)
message2 db 10,13, 'The string in lower case $'
.code
start:
mov ax, seg message1
mov ds, ax
mov dx, offset message1
mov ah,09h
int 21h
mov dx,offset string
mov ah,0Ah
int 21h
mov dx, offset message2
mov ah,09h
int 21h
mov di, offset string
inc di
mov bl,[di]
mov bh,0
inc di
mov BYTE PTR [BX+di],'$'
add bx, 2
lowercase:
cmp byte ptr [bx], 'a'
jb character
cmp byte ptr [bx], 'z'
ja character
and byte ptr [bx], 11011111b
character:
inc bx
loop lowercase
mov dx, di
mov ah,09h
int 21h
mov ax,4c00h
int 21h
End start
EXAMPLE2
;convert.asm
.model small
.stack 200h
.data
message1 Db 'abCdEF ghO/"0()ijklwmohcoc$'
.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
lodsb
and al, 11011111b
mov [si-1], al
jmp To_Uppercase
Done:
ret
mov ah,0
int 16h
Last:
mov ax,4c00h
int 21h
End start