; stdlib.h -- Standard interface definitons for the Hawk monitor. ; language: SMAL32 assembly language, intended as an include file ; author: Douglas W. Jones ; date: Dec 1, 2019 ; Linkage conventions: ; R1 -- used for return address linkage by all support routines. ; R2 -- available for use as an activation record pointer. ; R3 -- typically the first parameter and function return value ; R4 -- typically the second parameter, if there is one. ;------------------------------- ; the one universal monitor service EXT EXIT ; terminate application (same as return from main) ; touches nothing, all registers can be inspected ; C equivalent: exit(status) ;------------------------------- ; arithmetic routines EXT TIMES ; multiply two signed integers EXT TIMESU ; multiply two unsigned integers ; takes R3=multiplicand R4=multiplier ; returns R3=product ; wipes out R4-R6 ; C equivalent: product = multiplier * multiplicand EXT DIVIDEU ; divide two unsigned integers ; takes R3=dividend R4=divisor ; returns R3=quotient R4=remainder ; wipes out R5-R6 ; C equivalent: quotient = dividend / divisor ; remainder = dividend % divisor EXT RAND ; pseudo-random number generator ; returns R3=e, next element in pseudo-random stream ; note 0 <= e <= RAND_MAX ; wipes out R4-R6 ; C equivalent: e = rand() RAND_MAX= 32767 ;------------------------------- ; heap management EXT MALLOC ; allocate memory on the heap ; takes R3=size of desired memory region in bytes ; returns R3=pointer to a block of memory or NULL ; note NULL is returned when no memory is available ; if not null, the block will be word aligned ; and it will be big enouth to hold size bytes ; wipes out R4-R7 ; C equivalent: block = malloc(size) EXT FREE ; return unneeded memory to the heap ; takes R3=pointer to a memory block ; note that R3 must point to a block previously ; returned by malloc and not previously freed ; wipes out R4 ; C equivalent: free(block) NULL = 0 ; duplicates definition in stdio.h