Skip to content

Instantly share code, notes, and snippets.

@taylorlapeyre
Created March 11, 2014 15:51
Show Gist options
  • Save taylorlapeyre/9488633 to your computer and use it in GitHub Desktop.
Save taylorlapeyre/9488633 to your computer and use it in GitHub Desktop.
/*
* int i = 0;
* int nl = 0;
* while (S[i]) {
* if (S[i] > 97 && S[i] < 122) {
* nl++;
* }
* i++;
* }
*/
/*
* my registers: %eax, %edx, %ecx
* other registers: %esi, %ebp, ...
*/
#define II %edx
#define NL %eax
#define CH %cl
#define STR %esi
#define FSIZE 4
.text
.globl _numLowerCase
_numLowerCase:
sub $FSIZE, %esp
movl %esi, (%esp)
movl FSIZE+4(%esp), STR
xor II, II
xor NL, NL
LOOP1:
movb (STR, II), CH
cmp $0, CH
je DONE
cmp $97, CH
jl SKIP
cmp $122, CH
jg SKIP
inc NL
SKIP:
inc II
jmp LOOP1
DONE:
movl (%esp), %esi
add $FSIZE, %esp
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment