blob: 112d33cc48fc19af4e5ee9976f771a6381e7fb37 [file] [log] [blame]
Jari Aalto726f6381996-08-26 18:22:31 +00001;; alloca386.s 1.2
2;; GNU-compatible stack allocation function for Xenix/386.
3;; Written by Chip Salzenberg at ComDev.
4;; Last modified 90/01/11
5;;> Is your alloca clearly better than the one in i386-alloca.s? I haven't
6;;> looked at either.
7;;
8;;They're different because Xenix/386 has a different assembler. SCO
9;;Xenix has the Microsoft C compiler and the Microsoft macro assembler,
10;;called "masm". MASM's assembler syntax is quite different from AT&T's
11;;in all sorts of ways. Xenix people can't use the AT&T version.
12;;--
13;;Chip Salzenberg at ComDev/TCT <chip@tct.uucp>, <uunet!ateng!tct!chip>
14
15 TITLE $alloca386
16
17 .386
18DGROUP GROUP CONST, _BSS, _DATA
19_DATA SEGMENT DWORD USE32 PUBLIC 'DATA'
20_DATA ENDS
21_BSS SEGMENT DWORD USE32 PUBLIC 'BSS'
22_BSS ENDS
23CONST SEGMENT DWORD USE32 PUBLIC 'CONST'
24CONST ENDS
25_TEXT SEGMENT DWORD USE32 PUBLIC 'CODE'
26 ASSUME CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
27
28 PUBLIC _alloca
29_alloca PROC NEAR
30
31; Get argument.
32 pop edx ; edx -> return address
33 pop eax ; eax = amount to allocate
34
35; Validate allocation amount.
36 add eax,3
37 and eax,not 3
38 cmp eax,0
39 jg aa_size_ok
40 mov eax,4
41aa_size_ok:
42
43; Allocate stack space.
44 mov ecx,esp ; ecx -> old stack pointer
45 sub esp,eax ; perform allocation
46 mov eax,esp ; eax -> new stack pointer
47
48; Copy the three saved register variables from old stack top to new stack top.
49; They may not be there. So we waste twelve bytes. Big fat hairy deal.
50 push DWORD PTR 8[ecx]
51 push DWORD PTR 4[ecx]
52 push DWORD PTR 0[ecx]
53
54; Push something so the caller can pop it off.
55 push eax
56
57; Return to caller.
58 jmp edx
59
60_alloca ENDP
61
62_TEXT ENDS
63 END