check for this example - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

check for this example

nklnkl Posts: 14Member
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
«1

Comments

  • shaolin007shaolin007 Posts: 1,018Member
    : 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] [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]


  • nklnkl Posts: 14Member
    Sorry, i forget to mention that my program is written in TASM(assembly language), so could that program still be used?
  • shaolin007shaolin007 Posts: 1,018Member
    : Sorry, i forget to mention that my program is written in TASM(assembly language), so could that program still be used?
    :

    [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]

  • nklnkl Posts: 14Member
    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!!
  • shaolin007shaolin007 Posts: 1,018Member
    : 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!!
    :

    [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]

  • nklnkl Posts: 14Member
    thank you for your advice, i will try it. thank you very much...

  • nklnkl Posts: 14Member
    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

  • nklnkl Posts: 14Member
    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?



  • nklnkl Posts: 14Member
    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
  • nklnkl Posts: 14Member
    [b][red]This message was edited by nkl at 2005-10-12 8:32:26[/red][/b][hr]
    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


«1
Sign In or Register to comment.