flat assembler
Message board for the users of flat assembler.
Index
> Main > upper() and lower() |
Author |
|
LocoDelAssembly 16 Jun 2007, 18:46
Here my branchless version (which doesn't means that it's the most optimized in existence):
Code: upper:; AL = char to convert mov dl, al sub al, 'a' cmp al, 'z'-'a'+1 salc and al, 'A'-'a' add al, dl ret lower:; AL = char to convert mov dl, al sub al, 'A' cmp al, 'Z'-'A'+1 salc and al, 'a'-'A' add al, dl ret [edit] Code: upperLetter: ; AL = letter to convert and al, not $20 ret lowerLetter: ; AL = letter to convert or al, $20 ret Added Goplat's suggestion. Check below for remarks.[/edit] Last edited by LocoDelAssembly on 16 Jun 2007, 22:49; edited 1 time in total |
|||
16 Jun 2007, 18:46 |
|
Goplat 16 Jun 2007, 21:51
If all you're doing is checking for specific letters, rather than actually converting to lower/uppercase, you don't need to do real case mapping, a simple bit flip will do the trick. Lowercase letters have the same codes as uppercase with bit 5 set, so for example
Code: or al,20h cmp al,'q' je q_pressed will jump on either 'Q' or 'q'. Of course, punctation and such will get changed - eg, '@' becomes '`' - but none of them become letters, so the check is still safe. |
|||
16 Jun 2007, 21:51 |
|
LocoDelAssembly 16 Jun 2007, 22:56
I can't understand why I thought that trick was unsafe (without previous checkings) even on these cases :S
Well, maybe because I saw it about 6 years ago when I started with programming and in all these years I forgot to think again about it Thanks for pointing out this Goplat!! |
|||
16 Jun 2007, 22:56 |
|
Hayden 19 Jun 2007, 14:51
thanks guys
_________________ New User.. Hayden McKay. |
|||
19 Jun 2007, 14:51 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.