Hi,

I want to make a procedure which counts all lowercased letters. Now my program reads a character and counts all the characters

but i don't know how to count lowercased letters. Any tips? or procedures  :)
Posted on 2007-09-27 12:50:40 by w0lfas

Hi,

I want to make a procedure which counts all lowercased letters. Now my program reads a character and counts all the characters

but i don't know how to count lowercased letters. Any tips? or procedures  :)


Read up on ASCII.

Basically, you want to check if the character (byte) is between 0x61 and (including) 0x7A.

HtH :)
Posted on 2007-09-27 12:56:26 by SpooK
First check if it's lowercase and then count it.


buffer db "In the jungle the mighty jungle the lion sleeps tonight.",0

mov edx, offset buffer
xor ecx, ecx
.WHILE byte ptr != 0
 .IF byte ptr =< "a" && byte ptr >= "z"
    inc ecx
 .ENDIF
inc edx
.ENDW


Without the HLL thingies as follows:


mov edx, offset buffer
dec edx
xor ecx, ecx
@loop_begin:
inc edx
cmp byte ptr , 0
jz @loop_end
cmp byte ptr , a
jb @loop_begin
cmp byte ptr , z
ja @loop_begin
inc ecx
jmp @loop_begin
@loop_end:


Cheers,
JimmyC
Posted on 2007-09-27 13:00:25 by JimmyClif
sounds like homework
Posted on 2007-09-27 23:27:59 by evlncrn8
Hi!

This is a few lines shorter than JimmyClif's example, enjoy  :)

...Flat Assembler...


_text db 'This is test',0

     lea    esi,[_text]
     xor    ecx,ecx
_next:
     lodsb
     cmp  al,'a'
     jb     @f
     cmp  al,'z'
     ja     @f
     inc    ecx
@@: 
     test  al,al
     jnz  _next


Result in ecx...

Of course you can replace  'a' and 'z' with 'A' and 'Z' and you will count UpperCase letters. ('0' ... '9' and you will count digits)
Posted on 2007-09-28 02:36:37 by Kr!z
As usual, all of the above solutions will only work with English input... do you just need this for a homework assignment, or does it need to work for real-world input? ;)
Posted on 2007-09-28 03:59:37 by f0dder
It's a homework but not in assembler. I need to write this program in pascal (for my informatics lesson) but since I will be studying assembler in university next year(i hope so  ;)) so i want to get used to it earlier  ;)
Thanks for your ideas Kr!z and Jimmyclif. Now i need to understand them and keep on going to more difficult tasks. Probably ill need some more help in future, too :)
Posted on 2007-09-28 11:22:38 by w0lfas
Pascal hmm?


function CountLowerCase(s:string):byte assembler;
asm
        push  ds
        lea  si,
        xor  cx,cx
@next: lodsb
        cmp  al,'a'
        jb    @no_inc_cx
        cmp  al,'z'
        ja    @no_inc_cx
        inc    cx
@no_inc_cx:
        test  al,al
        jnz  @next
        mov  @result,cl
        pop  ds
end;


If you need more examples, more string routines and pascal/assembler code
look at the SWAG library:

SWAG:    http://bsdg.org/SWAG/

SWAG\Strings :  http://bsdg.org/SWAG/STRINGS/index.html




Posted on 2007-09-28 13:02:09 by Kr!z
oh come on.. hows that pascal
its inline asm....
Posted on 2007-09-28 18:15:37 by evlncrn8
Ah, good old pascal... I remember the SWAG days fondly *sniff*.

evlncrn8: back in the turbo/borland pascal days, most stuff had a good amount of inline assembly in it. The pascal compiler didn't optimize super well, and the CPUs back then were s-l-o-w. Assembly really did matter back then ;)
Posted on 2007-09-28 21:24:54 by f0dder
oh, i remember those days only too well :)
but i think if he submits that code with inline, he'll probably get in trouble with his teacher...
Posted on 2007-09-29 02:20:01 by evlncrn8

oh, i remember those days only too well :)
but i think if he submits that code with inline, he'll probably get in trouble with his teacher...


Or he gets the higher grade... I know from my own experience, if the teacher is smart then w0lfas will get the higher grade, but if the teacher is stupid and don't like people to be smarter than he/she is, w0lfas will get in trouble... :)



Posted on 2007-09-29 03:51:13 by Kr!z
Actually, i should write this prog just in pascal with no assembler implementation. That's very easy, so i wanted to do smth more complicated. So i thought to do that prog in _flat_ assembler. :)
However, my pascal compiler can't understand Kr!z's pascal function nor Kr!z's _flat_ assembler code (i use emu8086).
Posted on 2007-09-30 14:13:06 by w0lfas


oh, i remember those days only too well :)
but i think if he submits that code with inline, he'll probably get in trouble with his teacher...


Or he gets the higher grade... I know from my own experience, if the teacher is smart then w0lfas will get the higher grade, but if the teacher is stupid and don't like people to be smarter than he/she is, w0lfas will get in trouble... :)


That is a hasty generalization. What about the fact that inline ASM deviates from the process of learning PASCAL??? Elitism is no substitute for course requirements ;)
Posted on 2007-09-30 14:33:42 by SpooK
Hi

To w0lfas

So i thought to do that prog in _flat_ assembler.
However, my pascal compiler can't understand Kr!z's pascal function nor Kr!z's _flat_ assembler code (i use emu8086).


This pascal function I wrote in Delphi, I don't have an old/dos pascal compiler, tell me more what error you see. About the _flat_ assembler code, it compiles well on my version of flat, and of course I didn't check it on emu8086 maybe you should use 16-bit registers instead of 32-bit, replace esi,ecx with si,cx. Again, tell me more what errors you see...

To SpooK

That is a hasty generalization. What about the fact that inline ASM deviates from the process of learning PASCAL??? Elitism is no substitute for course requirements


You right, however inline ASM or "standalone" assembler should be the part of  the process of learning PASCAL/C++ languages because understanding assembler will helps understand the important aspects of programming (memory models, pointers, optimization, etc.) Everything depends of school and teacher. If someone want to be a good coder/programmer should have its own learning process.



 







Posted on 2007-10-01 02:21:09 by Kr!z

You right, however inline ASM or "standalone" assembler should be the part of  the process of learning PASCAL/C++ languages because understanding assembler will helps understand the important aspects of programming (memory models, pointers, optimization, etc.) Everything depends of school and teacher. If someone want to be a good coder/programmer should have its own learning process.


Don't we all wish programmers were forced to be good at what they do ;)
Posted on 2007-10-01 07:52:39 by SpooK
i don't use old/dos pascal either. i use free pascal. The error occurs at the beggining of this function. (compiler says: syntax error: it should be ; (instead of assembler))
function CountLowerCase(s:string):byte (the cursor stands here)assembler;
Posted on 2007-10-01 08:28:44 by w0lfas