Let's call this subroutine putchar, it may be implemented as
follows:
.data
localbuf: .fill 1
.text
putchar:
push %eax
push %ebx
push %ecx
push %edx
movl $4,%eax
movl $1,%ebx
movl $localbuf,%ecx
movl $1,%edx
int $0x80
pop %edx
pop %ecx
pop %ebx
pop %eax
ret
In this implementation, we use a ``global'' variable localbuf
to pass information from the caller to the subroutine. In other
words, if we want to print the character J, we can do the
following:
movb $'J',localbuf
call putchar
This works, but it has a few problems.
localbuf is allocated
statically. Whether or not putchar is actually
being used. This does not seem wasteful even though
localbuf is only one character. However, it is the
principle that matters. Other subroutines can be a lot more
wasteful.
localbuf. This is rather cumbersome.
Copyright © 2009-04-16 by Tak Auyeung