x86 Assembly

Moderators: None (Apply to moderate this forum)
Number of threads: 4563
Number of posts: 16029

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
check for this example Posted by nkl on 12 Oct 2005 at 5:36 AM
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
Report
Re: check for this example Posted by shaolin007 on 12 Oct 2005 at 6:47 AM
: 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] whats all this for? Your index is di. What if you had a junk value in di
: mov bh,0
:
:
: mov BYTE PTR [BX+di],'$' ???
: add bx, 2
:
: lowercase:
: cmp byte ptr [bx], 'a'
: jb character Not needed
: 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
:


Maybe

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", '$'


Here's a program that takes input from the keyboard that I made and converts to uppercase.
			;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



Report
Re: check for this example Posted by nkl on 12 Oct 2005 at 7:17 AM
Sorry, i forget to mention that my program is written in TASM(assembly language), so could that program still be used?
Report
Re: check for this example Posted by shaolin007 on 12 Oct 2005 at 7:24 AM
: Sorry, i forget to mention that my program is written in TASM(assembly language), so could that program still be used?
:


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.


Report
Re: check for this example Posted by nkl on 12 Oct 2005 at 7:48 AM
Here is my successful program which can convert the input which typed by the user. But now my new task is to convert the input which already insert in front of program. I fail to modify this program.So please help me..

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
Report
Re: check for this example Posted by nkl on 12 Oct 2005 at 7:25 AM
beside, the input is not typed by the user, but input is already in the program. The program just need to scan the data given and scan it and convert it to uppercase.And this program need written in TASM, so who is kind people, please help me!!
Report
Re: check for this example Posted by shaolin007 on 12 Oct 2005 at 7:27 AM
: beside, the input is not typed by the user, but input is already in the program. The program just need to scan the data given and scan it and convert it to uppercase.And this program need written in TASM, so who is kind people, please help me!!
:


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.


Report
Re: check for this example Posted by nkl on 12 Oct 2005 at 7:30 AM
thank you for your advice, i will try it. thank you very much...

Report
Re: check for this example Posted by nkl on 12 Oct 2005 at 7:41 AM
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
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

Report
Re: check for this example Posted by shaolin007 on 12 Oct 2005 at 8:03 AM

I'm not familiar with TASM syntax but try this.


: 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
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

mov ah,0
int 16h

: Last:
: mov ax,4c00h
: int 21h
: End start

: To_Uppercase:
cmp byte ptr [si], '$'
: je Done
: lodsb
: and al, 11011111b
mov [si-1], al
: jmp To_Uppercase
:
: Done:
: ret


Report
Re: check for this example Posted by nkl on 12 Oct 2005 at 8:19 AM
this time i try this program. But i fail to run the program.SO please help me check this program..

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


Report
Re: check for this example Posted by shaolin007 on 12 Oct 2005 at 8:38 AM
: this time i try this program. But i fail to run the program.SO please help me check this program..
:
: EXAMPLE
: ;convert.asm
: .model small
: .stack 200h
: .data
message1 Db '1abCdEF 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
:
:
:

Report
Re: check for this example Posted by nkl on 12 Oct 2005 at 7:55 AM
This message was edited by nkl at 2005-10-12 8:32:26

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


Report
Re: check for this example Posted by nkl on 12 Oct 2005 at 7:45 AM
Besides, i can't understand, what is the meaning for thatb i no need to check for a letter to convert to uppercase or even lowercase. Why i need to clear bit 5?For what purpose?



Report
Re: check for this example Posted by shaolin007 on 12 Oct 2005 at 8:08 AM
: Besides, i can't understand, what is the meaning for thatb i no need to check for a letter to convert to uppercase or even lowercase. Why i need to clear bit 5?For what purpose?
:
:
:
:


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
'A' = 0100 0001
'a' = 0110 0001

bit 5 is off in regards to uppercase while in lowercase it is on.



Report
Re: check for this example Posted by nkl on 12 Oct 2005 at 8:40 AM
This message was edited by nkl at 2005-10-12 8:51:57

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









 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.