.data maxwordlen = 20 word: .org +maxwordlen wordlen: .long 0x00 # word length initialized to 0 chread: .byte 0x00 # read into this location .text .global _start _start: movl $0, wordlen # redundant, but good programming practice loopBegin: # attempt to read one character into chread movl $3, %eax movl $0, %ebx movl $chread, %ecx movl $1, %edx int $0x80 # check if anything is actually read cmpl $0, %eax jz loopEnd # if nothing is read, skip to end of the loop # now we are in the loop body cmpb $'0', chread jb notalphanum cmpb $'9', chread jna alphanum cmpb $'A', chread jb notalphanum cmpb $'Z', chread jna alphanum cmpb $'a', chread jb notalphanum cmpb $'z', chread ja notalphanum alphanum: # now that we know chread is alphanumeric movl wordlen, %ecx movb chread, %al movb %al, word(,%ecx) addl $1, wordlen jmp loopBegin # yes, I cheated here to combine two jumps into one notalphanum: cmpl $0, wordlen jz loopBegin # yes, I cheated again movl wordlen, %edx movb $10, word(,%edx) addl $1, %edx movl $4, %eax movl $1, %ebx movl $word, %ecx # no need to initialize edx, guess why int $0x80 movl $0, wordlen jmp loopBegin loopEnd: cmpl $0, wordlen jz bye movl wordlen, %edx movb $10, word(,%edx) addl $1, %edx movl $4, %eax movl $1, %ebx movl $word, %ecx int $0x80 bye: movl $1,%eax movl $0,%ebx int $0x80