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 :)
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 :)
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 :)
First check if it's lowercase and then count it.
Without the HLL thingies as follows:
Cheers,
JimmyC
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
sounds like homework
Hi!
This is a few lines shorter than JimmyClif's example, enjoy :)
...Flat Assembler...
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)
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)
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? ;)
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 :)
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 :)
Pascal hmm?
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
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
oh come on.. hows that pascal
its inline asm....
its inline asm....
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 ;)
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 ;)
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...
but i think if he submits that code with inline, he'll probably get in trouble with his teacher...
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... :)
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).
However, my pascal compiler can't understand Kr!z's pascal function nor Kr!z's _flat_ assembler code (i use emu8086).
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 ;)
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.
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.
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 ;)
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;