how can i write a program, which accepts the starting address (in BX) of a text (terminated by a “%”) stored in data segment and replace all lower-case letters by their upper-case counterparts. Non-alphetic characters will remain as is.(8086)

Show us what you can do and we'll help you where you get stuck.

You will need a loop and two conditional checks to see if the letter needs to be converted to uppercase.

I assume ASCII?

name "upper"

org 100h


jmp start

string db '123 test TEsting$'

start: lea bx, string

upper_case:

; check if it's a lower case letter:
cmp byte ptr [bx], 'a'
jb ok
cmp byte ptr [bx], 'z'
ja ok

; convert to uppercase:

; upper case letter do not have
; third bit set, for example:
; 'a' : 01100001b
; 'a' : 01000001b
; upper case mask : 11011111b

; clear third bit:
and byte ptr [bx], 11011111b

ok:
inc bx ; next char.
loop upper_case


; int 21h / ah=09h - output of a string at ds:dx.
; string must be terminated by '$' sign.
lea dx, string
mov ah, 09h
int 21h

; wait for any key press....
mov ah, 0
int 16h


null:
ret ;

Good start. I'm using MASM, so I don't know if some of my remarks are accounted for or not.

one
You need to load DS with the proper value. Generally data and code are separated into different segments, but they need not be. You'll need to start with some directives about the memory model also...

.model small
.stack 64

.data
        string db '123 test TEsting$'

.code
start:
        mov ax, @data
        mov ds, ax

        ...

end start

two
The loop opcode relies on CX. You have used loop but you have not initialized CX. Therefore, your loop will execute some random number of times.

To test your code, I just added lea bx, string mov cx, 16 uppercase: since your string is 16 characters long (not counting the '$').

However, this is not a good solution. Instead of using loop, why not test to see if byte ptr [bx] is the '$' character, and jump to the beginning of the loop if it is not? That way your string can be any length...


three
Always halt your program with:

; terminate with return code 0
        mov ax, 4C00h
        int 21h

You can of course change the return code as required. Zero indicates normal termination.


Hope this helps.

.model small
.data

            string db '123 test TEsting$'

.code 

start:          
            mov ax, @data
            mov ds, ax          

upper_case: 
            cmp [bx], '$'
            
            je done
            
            ; check if it's a lower case letter:
            cmp byte ptr [bx], 'a'
            jb ok
            cmp byte ptr [bx], 'z'
            ja ok

            and byte ptr [bx], 11011111b

ok:
            inc bx ; next char.
            jmp upper_case   


done:

            lea dx, string
            mov ah, 09h
            int 21h
         
            ; wait for any key press....
            mov ah, 0
            int 16h   
        
            mov ax, 4C00h
        
            int 21h


end start

:S

Very nice! Good job!

1. Line 11: You forgot to initialize BX with the address of "string".
2. Line 13: You forgot to give a size: cmp [B]byte ptr[/B] [BX], '$' Personally, I would remove lines 36..38 since it serves no purpose. If you are going to ask the user to press a key, first print a message telling him to do it.

Also, I'd add just a few more comments: what are lines 13..15 doing? what is line 23 doing? and 32..34? and 40..42? Just a one-line synopsis (like in my example under "three" above) will do.

I'd give this an A (once 1 and 2 are fixed, that is).

what do I do if I need to convert uppercase to lowercase and lowercase to uppercase
i assume i need to add something like jmp lowercase
add stuffs in there then cmp, je ok
next char..

but how exactly can i do that..
i have very little understanding asm language.. so i need to ask what is what..
don't worry, im capable of understanding it..though i need a little bit of explanation..

thanks..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.