Xenix/386 alloca()
Chip Salzenberg
chip at ateng.ateng.com
Tue Mar 28 03:40:48 AEST 1989
Several persons have requested alloca() for Xenix/386. Okay, here it is.
Written in Microsoft assembler, it works with the Xenix/386 C compiler.
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of shell archive."
# Contents: Makefile alloca.s
# Wrapped by chip at ateng on Mon Mar 27 12:39:18 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Makefile' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(236 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X# Makefile for alloca
X
XTARGET=Sliballoc.a
XASFLAGS=-Mx $(LISTING)
X
Xall: $(TARGET)
X
Xclean:
X rm -f *.o ?liballoc.a
X
XSliballoc.a: alloca.s
X $(AS) $(ASFLAGS) -DMODEL_$(MODEL) -oalloca.o alloca.s
X ar ru $@ alloca.o
X rm alloca.o
X ranlib $@
END_OF_FILE
if test 236 -ne `wc -c <'Makefile'`; then
echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'alloca.s' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'alloca.s'\"
else
echo shar: Extracting \"'alloca.s'\" \(1075 characters\)
sed "s/^X//" >'alloca.s' <<'END_OF_FILE'
X; alloca.s
X; Allocate from the stack from a Microsoft C program.
X
X TITLE $alloca386
X
X .386
X
X_DATA SEGMENT DWORD USE32 PUBLIC 'DATA'
X_DATA ENDS
XCONST SEGMENT DWORD USE32 PUBLIC 'CONST'
XCONST ENDS
X_BSS SEGMENT DWORD USE32 PUBLIC 'BSS'
X_BSS ENDS
XDGROUP GROUP CONST, _BSS, _DATA
X
X_TEXT SEGMENT DWORD USE32 PUBLIC 'CODE'
X_TEXT ENDS
X
X ASSUME CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
X_TEXT SEGMENT
X
X PUBLIC _alloca
X
X_alloca PROC NEAR
X
X;; Pop return address into edx and size into eax
X pop edx
X pop eax
X
X;; Make sure that eax is greater than zero, and is a multiple of four.
X cmp eax,0
X jg short pos
X mov eax,4
Xpos:
X add eax,3
X and eax,not 3
X
X;; Remember old stack pointer
X mov ecx,esp
X
X;; Figure new stack pointer, our return value.
X sub esp,eax
X mov eax,esp
X
X;; Copy the (hypothetical) register variables.
X push [ecx+8]
X push [ecx+4]
X push [ecx+0]
X
X;; Put something on the stack so that our caller can pop it off.
X push eax
X
X;; Return to the the caller.
X jmp edx
X
X_alloca ENDP
X
X_TEXT ENDS
X
X END
END_OF_FILE
if test 1075 -ne `wc -c <'alloca.s'`; then
echo shar: \"'alloca.s'\" unpacked with wrong size!
fi
# end of 'alloca.s'
fi
echo shar: End of shell archive.
exit 0
--
Chip Salzenberg <chip at ateng.com> or <uunet!ateng!chip>
A T Engineering Me? Speak for my company? Surely you jest!
"It's no good. They're tapping the lines."
More information about the Alt.sources
mailing list