Category : C Source Code
Archive   : ALLOCAAP.ZIP
Filename : ALLOCA.8

 
Output of file : ALLOCA.8 contained in archive : ALLOCAAP.ZIP
;
; alloca.8 begins
; source for a86 assembler
; released into the public domain with the restriction that the
; acknowledgement below be preserved:
; ... This alloca() for Turbo C is by Alexander Pruss ...
;
; Assemble via:
; A86 +oc =____ alloca.8
; Note that the HUGE alloca = LARGE alloca and that TINY alloca = SMALL alloca
;
#if __MEDIUM__
L_CODE = 1
#elseif __COMPACT__
L_DATA = 1
#elseif __LARGE__
L_DATA = 1
L_CODE = 1
#elseif __HUGE__
L_DATA = 1
L_CODE = 1
#endif

#if L_CODE
ALLOCA_TEXT segment byte public 'CODE'
#else
TEXT segment byte public 'CODE'
#endif

@alloca_buffer dw ?

public __alloca
;; void *_alloca(unsigned size) ;;
__alloca:
pop bx ; Return address
#if L_CODE
pop es ; into [ES:]BX
#endif
pop cx ; Data size. (Argument to alloca)

pop dx ; Store some
pop ax
#if L_DATA

pop cs:@alloca_buffer ; data from caller's stack
push cs:@alloca_buffer ; (DS,SI,DI--some may not be necessary)
#endif ; DS unnecessary for small data models
push ax ; we put it back after reading
push dx
inc cx ; Round CX to even. (SP must be even,
; else performance degrades)
shr cx,1
shl cx,1
sub sp,cx ; Allocate the space

#if L_DATA
push cs:@alloca_buffer ; make a copy of the possible data
#endif
push ax ; (DS,SI,DI) on the caller's stack
push dx

mov ax,sp ; Return value.
#if L_DATA
add ax,8 ; remember we put 3 words on the stack
; and the stack points to a free word
#else
add ax,6 ; 2 words for small data models only
#endif
push cx ; put the size back on the stack
#if L_CODE
push es ; high order return address
#endif
push bx ; low order return address
#if L_DATA
mov dx,ss ; high order return value
#endif
#if L_CODE
retf ; out we go!
#else
ret
#endif

ALLOCA_TEXT ends
end


  3 Responses to “Category : C Source Code
Archive   : ALLOCAAP.ZIP
Filename : ALLOCA.8

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/