Hi All,

I have the following program to convert Lower case character to uppercase letters

org $4000
Alph equ 26 26 Alphabets

begin lea LC,A0 store lowercase to A0
lea UC,A1 store uppercase to A1
move.b #Alph,d1
sub.b #1,d1

loop move.b (A0)+,d0 convert LC to UC
sub.b #32,d0
move.b d0,(A1)+
dbra d0,loop goes back to loop
move.b #9,d0
TRAP #15


org $4100
LC dc.b 'computer hardware' define lowercase

org $4200
UC ds.b 26 reserve for uppercase
END begin

The results displayed as COMPUTER (the HARDWARE is missing I think its due to the spacing in between) I've had tried to define the spacing as follows

SP equ $20 Define ASCII code for spacing

But it still not working.
Anyone out there can help me? Did I do something wrong on my assembler? Please help.

Code tags!

org $4000
Alph equ 26 26 Alphabets

begin:
    lea LC,A0 store lowercase to A0
    lea UC,A1 store uppercase to A1
    move.b #Alph,d1
    sub.b #1,d1

loop:
    move.b (A0)+,d0 convert LC to UC
    sub.b #32,d0
    move.b d0,(A1)+
    dbra d0,loop goes back to loop

    move.b #9,d0
    TRAP #15


org $4100
LC dc.b 'computer hardware' define lowercase

org $4200
UC ds.b 26 reserve for uppercase
END begin

To terminate the loop you are using D0. It has a value of whatever has been loaded by mov (at line 11) less 32. Coincidentally, the ascii code for a space is 32. As soon as your program hits the space, the D0 value becomes 0, which breaks the loop.
Obviously, you want to control the loop by another data register; from what I see in your code, you tried to set up D1 for that purpose. The immediate question is why do you initialize it the way you do?
PS: you need some logic to convert only lowercase symbols.

Hi nezachem, thanks for your feedback...Basically I analysed the Ascii code table and found the trend that the difference between the lower case and uppercase letters is 32 in decimal...So if I would like to convert the the cases, I will either minus or add by 32. Correct me if I'm wrong. Cheers

Yes, that is correct. IF the characters are between 41H and 5AH, then subtract 32 from the char code to make lower... If the characters are between 61H and 7AH then add 32 to make upper.

Which is why I do not know why mmy output only shows as COMPUTER with the hardware word missing from it. My only suspicions is the spacing in between which cause the problem. And somehow I need to identify the char spacing somewhere. Please help :)

I explained why. Please reread my post. After that, please answer (in plain English, no code)
- how do you want the loop to terminate, and
- how does it actually terminates.
Then we can proceed.

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.