malloc - Allocate Memory Block

VAX11

 

malloc - Allocate Memory Block

 

malloc allocates a block of 'Size' bytes.

 

 

Returns: On R0: Pointer to allocated space.

                Returns NULL if the space cannot be allocated.

 

 

Notes:

One argument pushed into Stack = number of bytes to be allocated.

Use free to deallocate block allocated with malloc.

 

 

Example:

 

 

.text

main: .word 0

 

      pushl $0x100

      calls $1, .malloc

      pushl r0

      pushal format

      calls $2, .printf

 

      pushl $0x100

      calls $1, .malloc

      pushl r0

      pushal format

      calls $2, .printf

 

      pushl $0x100

      calls $1, .malloc

      pushl r0

      pushal format

      calls $2, .printf

 

      pushl $0x1119

      calls $1, .free

 

      pushl $0x100

      calls $1, .malloc

      pushl r0

      pushal format

      calls $2, .printf

 

      pushl $0

      calls $1, .exit

 

.org 0x1000

.data

format: .asciz "Address: 0x%08X\n"