bits 16

; glb CURSOR : [0u] char
section .data
	global	_CURSOR
_CURSOR:
; =
	db	"ZMS> "
	times	1 db 0

; glb uint16_t : unsigned
; glb int16_t : int
; glb uint8_t : unsigned char
; glb random : unsigned
section .data
	align 2
	global	_random
_random:
; =
; RPN'ized expression: "1 "
; Expanded expression: "1 "
; Expression value: 1
	dw	1

; glb get_memory_kb : (void) unsigned
_get_memory_kb:
int 0x12
ret

; glb command_registry : struct cmds
section .bss
	alignb 2
	global	_command_registry
_command_registry:
	resb	2

; glb TOTAL_HEAP_SIZE : unsigned
section .bss
	alignb 2
	global	_TOTAL_HEAP_SIZE
_TOTAL_HEAP_SIZE:
	resb	2

; glb memory_pool : * unsigned char
section .data
	align 2
	global	_memory_pool
_memory_pool:
; =
; glb <something> : * unsigned char
; RPN'ized expression: "12288 (something1) "
; Expanded expression: "12288 "
	dw	12288

; glb free_list_head : int
section .bss
	alignb 2
	global	_free_list_head
_free_list_head:
	resb	2

; RPN'ized expression: "64 "
; Expanded expression: "64 "
; Expression value: 64
; glb heap : [64u] struct mem_block
section .bss
	alignb 2
	global	_heap
_heap:
	resb	640

; glb init_heap : (void) void
section .text
	global	_init_heap
_init_heap:
	push	bp
	mov	bp, sp
	 sub	sp,          2
; RPN'ized expression: "TOTAL_HEAP_SIZE ( get_memory_kb ) 1024 * 12288 - = "
; Expanded expression: "TOTAL_HEAP_SIZE  get_memory_kb ()0 1024 * 12288 - =(2) "
; Fused expression:    "( get_memory_kb )0 * ax 1024 - ax 12288 =(170) *TOTAL_HEAP_SIZE ax "
	call	_get_memory_kb
	imul	ax, ax, 1024
	sub	ax, 12288
	mov	[_TOTAL_HEAP_SIZE], ax
; RPN'ized expression: "heap 0 + *u &u start -> *u 0 = "
; Expanded expression: "heap 0 + 0 + 0 =(2) "
; Fused expression:    "+ heap 0 + ax 0 =(170) *ax 0 "
	mov	ax, _heap
	mov	bx, ax
	mov	ax, 0
	mov	[bx], ax
; RPN'ized expression: "heap 0 + *u &u size -> *u TOTAL_HEAP_SIZE = "
; Expanded expression: "heap 0 + 2 + TOTAL_HEAP_SIZE *(2) =(2) "
; Fused expression:    "+ heap 0 + ax 2 =(170) *ax *TOTAL_HEAP_SIZE "
	mov	ax, _heap
	add	ax, 2
	mov	bx, ax
	mov	ax, [_TOTAL_HEAP_SIZE]
	mov	[bx], ax
; RPN'ized expression: "heap 0 + *u &u free -> *u 1 = "
; Expanded expression: "heap 0 + 4 + 1 =(1) "
; Fused expression:    "+ heap 0 + ax 4 =(154) *ax 1 "
	mov	ax, _heap
	add	ax, 4
	mov	bx, ax
	mov	ax, 1
	mov	[bx], al
	mov	ah, 0
; RPN'ized expression: "heap 0 + *u &u next_index -> *u 1 -u = "
; Expanded expression: "heap 0 + 6 + -1 =(2) "
; Fused expression:    "+ heap 0 + ax 6 =(170) *ax -1 "
	mov	ax, _heap
	add	ax, 6
	mov	bx, ax
	mov	ax, -1
	mov	[bx], ax
; RPN'ized expression: "heap 0 + *u &u used -> *u 1 = "
; Expanded expression: "heap 0 + 8 + 1 =(1) "
; Fused expression:    "+ heap 0 + ax 8 =(154) *ax 1 "
	mov	ax, _heap
	add	ax, 8
	mov	bx, ax
	mov	ax, 1
	mov	[bx], al
	mov	ah, 0
; RPN'ized expression: "free_list_head 0 = "
; Expanded expression: "free_list_head 0 =(2) "
; Fused expression:    "=(170) *free_list_head 0 "
	mov	ax, 0
	mov	[_free_list_head], ax
; for
; loc     i : (@-2) : int
; RPN'ized expression: "i 1 = "
; Expanded expression: "(@-2) 1 =(2) "
; Fused expression:    "=(170) *(@-2) 1 "
	mov	ax, 1
	mov	[bp-2], ax
L4:
; RPN'ized expression: "i 64 < "
; Expanded expression: "(@-2) *(2) 64 < "
; Fused expression:    "< *(@-2) 64 IF! "
	mov	ax, [bp-2]
	cmp	ax, 64
	jge	L7
; RPN'ized expression: "i ++p "
; Expanded expression: "(@-2) ++p(2) "
; {
; RPN'ized expression: "heap i + *u &u free -> *u 1 = "
; Expanded expression: "heap (@-2) *(2) 10 * + 4 + 1 =(1) "
; Fused expression:    "* *(@-2) 10 + heap ax + ax 4 =(154) *ax 1 "
	mov	ax, [bp-2]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	add	ax, 4
	mov	bx, ax
	mov	ax, 1
	mov	[bx], al
	mov	ah, 0
; RPN'ized expression: "heap i + *u &u next_index -> *u 1 -u = "
; Expanded expression: "heap (@-2) *(2) 10 * + 6 + -1 =(2) "
; Fused expression:    "* *(@-2) 10 + heap ax + ax 6 =(170) *ax -1 "
	mov	ax, [bp-2]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	add	ax, 6
	mov	bx, ax
	mov	ax, -1
	mov	[bx], ax
; }
L5:
; Fused expression:    "++p(2) *(@-2) "
	mov	ax, [bp-2]
	inc	word [bp-2]
	jmp	L4
L7:
L2:
	leave
	ret

; glb find_block : (
; prm     size : unsigned
;     ) int
section .text
	global	_find_block
_find_block:
	push	bp
	mov	bp, sp
	 sub	sp,          2
; loc     size : (@4) : unsigned
; loc     idx : (@-2) : int
; RPN'ized expression: "idx free_list_head = "
; Expanded expression: "(@-2) free_list_head *(2) =(2) "
; Fused expression:    "=(170) *(@-2) *free_list_head "
	mov	ax, [_free_list_head]
	mov	[bp-2], ax
; while
; RPN'ized expression: "idx 1 -u != "
; Expanded expression: "(@-2) *(2) -1 != "
L10:
; Fused expression:    "!= *(@-2) -1 IF! "
	mov	ax, [bp-2]
	cmp	ax, -1
	je	L11
; {
; if
; RPN'ized expression: "heap idx + *u &u free -> *u heap idx + *u &u size -> *u size >= && "
; Expanded expression: "heap (@-2) *(2) 10 * + 4 + *(1) _Bool [sh&&->14] heap (@-2) *(2) 10 * + 2 + *(2) (@4) *(2) >=u &&[14] "
; Fused expression:    "* *(@-2) 10 + heap ax + ax 4 *(1) ax _Bool [sh&&->14] * *(@-2) 10 + heap ax + ax 2 >=u *ax *(@4) &&[14]  "
	mov	ax, [bp-2]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	add	ax, 4
	mov	bx, ax
	mov	al, [bx]
	mov	ah, 0
	test	ax, ax
	setne	al
	cbw
; JumpIfZero
	test	ax, ax
	je	L14
	mov	ax, [bp-2]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	add	ax, 2
	mov	bx, ax
	mov	ax, [bx]
	cmp	ax, [bp+4]
	setae	al
	cbw
L14:
; JumpIfZero
	test	ax, ax
	je	L12
; {
; return
; RPN'ized expression: "idx "
; Expanded expression: "(@-2) *(2) "
; Fused expression:    "*(2) (@-2)  "
	mov	ax, [bp-2]
	jmp	L8
; }
L12:
; RPN'ized expression: "idx heap idx + *u &u next_index -> *u = "
; Expanded expression: "(@-2) heap (@-2) *(2) 10 * + 6 + *(2) =(2) "
; Fused expression:    "* *(@-2) 10 + heap ax + ax 6 =(170) *(@-2) *ax "
	mov	ax, [bp-2]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	add	ax, 6
	mov	bx, ax
	mov	ax, [bx]
	mov	[bp-2], ax
; }
	jmp	L10
L11:
; return
; RPN'ized expression: "1 -u "
; Expanded expression: "-1 "
; Expression value: -1
; Fused expression:    "-1  "
	mov	ax, -1
L8:
	leave
	ret

; glb find_free_struct_block : () int
section .text
	global	_find_free_struct_block
_find_free_struct_block:
	push	bp
	mov	bp, sp
	 sub	sp,          2
; for
; loc     i : (@-2) : int
; RPN'ized expression: "i 0 = "
; Expanded expression: "(@-2) 0 =(2) "
; Fused expression:    "=(170) *(@-2) 0 "
	mov	ax, 0
	mov	[bp-2], ax
L17:
; RPN'ized expression: "i 64 < "
; Expanded expression: "(@-2) *(2) 64 < "
; Fused expression:    "< *(@-2) 64 IF! "
	mov	ax, [bp-2]
	cmp	ax, 64
	jge	L20
; RPN'ized expression: "i ++p "
; Expanded expression: "(@-2) ++p(2) "
; {
; if
; RPN'ized expression: "heap i + *u &u used -> *u 0 == "
; Expanded expression: "heap (@-2) *(2) 10 * + 8 + *(1) 0 == "
; Fused expression:    "* *(@-2) 10 + heap ax + ax 8 == *ax 0 IF! "
	mov	ax, [bp-2]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	add	ax, 8
	mov	bx, ax
	mov	al, [bx]
	mov	ah, 0
	cmp	ax, 0
	jne	L21
; {
; return
; RPN'ized expression: "i "
; Expanded expression: "(@-2) *(2) "
; Fused expression:    "*(2) (@-2)  "
	mov	ax, [bp-2]
	jmp	L15
; }
L21:
; }
L18:
; Fused expression:    "++p(2) *(@-2) "
	mov	ax, [bp-2]
	inc	word [bp-2]
	jmp	L17
L20:
; return
; RPN'ized expression: "1 -u "
; Expanded expression: "-1 "
; Expression value: -1
; Fused expression:    "-1  "
	mov	ax, -1
L15:
	leave
	ret

; glb alloc : (
; prm     size : unsigned
;     ) int
section .text
	global	_alloc
_alloc:
	push	bp
	mov	bp, sp
	 sub	sp,          6
; loc     size : (@4) : unsigned
; loc     idx : (@-2) : int
; RPN'ized expression: "idx ( size find_block ) = "
; Expanded expression: "(@-2)  (@4) *(2)  find_block ()2 =(2) "
; Fused expression:    "( *(2) (@4) , find_block )2 =(170) *(@-2) ax "
	push	word [bp+4]
	call	_find_block
	sub	sp, -2
	mov	[bp-2], ax
; if
; RPN'ized expression: "idx 1 -u == "
; Expanded expression: "(@-2) *(2) -1 == "
; Fused expression:    "== *(@-2) -1 IF! "
	mov	ax, [bp-2]
	cmp	ax, -1
	jne	L25
; return
; RPN'ized expression: "1 -u "
; Expanded expression: "-1 "
; Expression value: -1
; Fused expression:    "-1  "
	mov	ax, -1
	jmp	L23
L25:
; loc     b : (@-4) : * struct mem_block
; RPN'ized expression: "b heap idx + *u &u = "
; Expanded expression: "(@-4) heap (@-2) *(2) 10 * + =(2) "
; Fused expression:    "* *(@-2) 10 + heap ax =(170) *(@-4) ax "
	mov	ax, [bp-2]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	mov	[bp-4], ax
; if
; RPN'ized expression: "b size -> *u size > "
; Expanded expression: "(@-4) *(2) 2 + *(2) (@4) *(2) >u "
; Fused expression:    "+ *(@-4) 2 >u *ax *(@4) IF! "
	mov	ax, [bp-4]
	add	ax, 2
	mov	bx, ax
	mov	ax, [bx]
	cmp	ax, [bp+4]
	jbe	L27
; {
; loc         new_idx : (@-6) : int
; RPN'ized expression: "new_idx ( find_free_struct_block ) = "
; Expanded expression: "(@-6)  find_free_struct_block ()0 =(2) "
; Fused expression:    "( find_free_struct_block )0 =(170) *(@-6) ax "
	call	_find_free_struct_block
	mov	[bp-6], ax
; RPN'ized expression: "heap new_idx + *u &u start -> *u b start -> *u size + = "
; Expanded expression: "heap (@-6) *(2) 10 * + 0 + (@-4) *(2) 0 + *(2) (@4) *(2) + =(2) "
; Fused expression:    "* *(@-6) 10 + heap ax + ax 0 push-ax + *(@-4) 0 + *ax *(@4) =(170) **sp ax "
	mov	ax, [bp-6]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	push	ax
	mov	ax, [bp-4]
	mov	bx, ax
	mov	ax, [bx]
	add	ax, [bp+4]
	pop	bx
	mov	[bx], ax
; RPN'ized expression: "heap new_idx + *u &u size -> *u b size -> *u size - = "
; Expanded expression: "heap (@-6) *(2) 10 * + 2 + (@-4) *(2) 2 + *(2) (@4) *(2) - =(2) "
; Fused expression:    "* *(@-6) 10 + heap ax + ax 2 push-ax + *(@-4) 2 - *ax *(@4) =(170) **sp ax "
	mov	ax, [bp-6]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	add	ax, 2
	push	ax
	mov	ax, [bp-4]
	add	ax, 2
	mov	bx, ax
	mov	ax, [bx]
	sub	ax, [bp+4]
	pop	bx
	mov	[bx], ax
; RPN'ized expression: "heap new_idx + *u &u free -> *u 1 = "
; Expanded expression: "heap (@-6) *(2) 10 * + 4 + 1 =(1) "
; Fused expression:    "* *(@-6) 10 + heap ax + ax 4 =(154) *ax 1 "
	mov	ax, [bp-6]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	add	ax, 4
	mov	bx, ax
	mov	ax, 1
	mov	[bx], al
	mov	ah, 0
; RPN'ized expression: "heap new_idx + *u &u next_index -> *u b next_index -> *u = "
; Expanded expression: "heap (@-6) *(2) 10 * + 6 + (@-4) *(2) 6 + *(2) =(2) "
; Fused expression:    "* *(@-6) 10 + heap ax + ax 6 push-ax + *(@-4) 6 =(170) **sp *ax "
	mov	ax, [bp-6]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	add	ax, 6
	push	ax
	mov	ax, [bp-4]
	add	ax, 6
	mov	bx, ax
	mov	ax, [bx]
	pop	bx
	mov	[bx], ax
; RPN'ized expression: "heap new_idx + *u &u used -> *u 1 = "
; Expanded expression: "heap (@-6) *(2) 10 * + 8 + 1 =(1) "
; Fused expression:    "* *(@-6) 10 + heap ax + ax 8 =(154) *ax 1 "
	mov	ax, [bp-6]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	add	ax, 8
	mov	bx, ax
	mov	ax, 1
	mov	[bx], al
	mov	ah, 0
; RPN'ized expression: "b size -> *u size = "
; Expanded expression: "(@-4) *(2) 2 + (@4) *(2) =(2) "
; Fused expression:    "+ *(@-4) 2 =(170) *ax *(@4) "
	mov	ax, [bp-4]
	add	ax, 2
	mov	bx, ax
	mov	ax, [bp+4]
	mov	[bx], ax
; RPN'ized expression: "b next_index -> *u new_idx = "
; Expanded expression: "(@-4) *(2) 6 + (@-6) *(2) =(2) "
; Fused expression:    "+ *(@-4) 6 =(170) *ax *(@-6) "
	mov	ax, [bp-4]
	add	ax, 6
	mov	bx, ax
	mov	ax, [bp-6]
	mov	[bx], ax
; }
L27:
; RPN'ized expression: "b free -> *u 0 = "
; Expanded expression: "(@-4) *(2) 4 + 0 =(1) "
; Fused expression:    "+ *(@-4) 4 =(154) *ax 0 "
	mov	ax, [bp-4]
	add	ax, 4
	mov	bx, ax
	mov	ax, 0
	mov	[bx], al
	mov	ah, 0

section .rodata
L29:
	db	"Allocated block starting at "
	times	1 db 0

section .text
; RPN'ized expression: "( L29 print ) "
; Expanded expression: " L29  print ()2 "
; Fused expression:    "( L29 , print )2 "
	push	L29
	call	_print
	sub	sp, -2
; RPN'ized expression: "( heap idx + *u &u start -> *u print_hex_word ) "
; Expanded expression: " heap (@-2) *(2) 10 * + 0 + *(2)  print_hex_word ()2 "
; Fused expression:    "( * *(@-2) 10 + heap ax + ax 0 *(2) ax , print_hex_word )2 "
	mov	ax, [bp-2]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	mov	bx, ax
	push	word [bx]
	call	_print_hex_word
	sub	sp, -2

section .rodata
L30:
	db	" and continuing for "
	times	1 db 0

section .text
; RPN'ized expression: "( L30 print ) "
; Expanded expression: " L30  print ()2 "
; Fused expression:    "( L30 , print )2 "
	push	L30
	call	_print
	sub	sp, -2
; RPN'ized expression: "( size print_hex_word ) "
; Expanded expression: " (@4) *(2)  print_hex_word ()2 "
; Fused expression:    "( *(2) (@4) , print_hex_word )2 "
	push	word [bp+4]
	call	_print_hex_word
	sub	sp, -2

section .rodata
L31:
	db	13,10
	times	1 db 0

section .text
; RPN'ized expression: "( L31 print ) "
; Expanded expression: " L31  print ()2 "
; Fused expression:    "( L31 , print )2 "
	push	L31
	call	_print
	sub	sp, -2
; return
; RPN'ized expression: "idx "
; Expanded expression: "(@-2) *(2) "
; Fused expression:    "*(2) (@-2)  "
	mov	ax, [bp-2]
L23:
	leave
	ret

; glb free_block : (
; prm     idx : int
;     ) void
section .text
	global	_free_block
_free_block:
	push	bp
	mov	bp, sp
	 sub	sp,          2
; loc     idx : (@4) : int
; RPN'ized expression: "heap idx + *u &u free -> *u 1 = "
; Expanded expression: "heap (@4) *(2) 10 * + 4 + 1 =(1) "
; Fused expression:    "* *(@4) 10 + heap ax + ax 4 =(154) *ax 1 "
	mov	ax, [bp+4]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	add	ax, 4
	mov	bx, ax
	mov	ax, 1
	mov	[bx], al
	mov	ah, 0
; loc     next : (@-2) : int
; RPN'ized expression: "next heap idx + *u &u next_index -> *u = "
; Expanded expression: "(@-2) heap (@4) *(2) 10 * + 6 + *(2) =(2) "
; Fused expression:    "* *(@4) 10 + heap ax + ax 6 =(170) *(@-2) *ax "
	mov	ax, [bp+4]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	add	ax, 6
	mov	bx, ax
	mov	ax, [bx]
	mov	[bp-2], ax
; if
; RPN'ized expression: "next 1 -u != heap next + *u &u free -> *u && "
; Expanded expression: "(@-2) *(2) -1 != [sh&&->36] heap (@-2) *(2) 10 * + 4 + *(1) _Bool &&[36] "
; Fused expression:    "!= *(@-2) -1 [sh&&->36] * *(@-2) 10 + heap ax + ax 4 *(1) ax _Bool &&[36]  "
	mov	ax, [bp-2]
	cmp	ax, -1
	setne	al
	cbw
; JumpIfZero
	test	ax, ax
	je	L36
	mov	ax, [bp-2]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	add	ax, 4
	mov	bx, ax
	mov	al, [bx]
	mov	ah, 0
	test	ax, ax
	setne	al
	cbw
L36:
; JumpIfZero
	test	ax, ax
	je	L34
; {
; RPN'ized expression: "heap idx + *u &u size -> *u heap next + *u &u size -> *u += "
; Expanded expression: "heap (@4) *(2) 10 * + 2 + heap (@-2) *(2) 10 * + 2 + *(2) +=(2) "
; Fused expression:    "* *(@4) 10 + heap ax + ax 2 push-ax * *(@-2) 10 + heap ax + ax 2 +=(170) **sp *ax "
	mov	ax, [bp+4]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	add	ax, 2
	push	ax
	mov	ax, [bp-2]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	add	ax, 2
	mov	bx, ax
	mov	cx, [bx]
	pop	bx
	mov	ax, [bx]
	add	ax, cx
	mov	[bx], ax
; RPN'ized expression: "heap idx + *u &u next_index -> *u heap next + *u &u next_index -> *u = "
; Expanded expression: "heap (@4) *(2) 10 * + 6 + heap (@-2) *(2) 10 * + 6 + *(2) =(2) "
; Fused expression:    "* *(@4) 10 + heap ax + ax 6 push-ax * *(@-2) 10 + heap ax + ax 6 =(170) **sp *ax "
	mov	ax, [bp+4]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	add	ax, 6
	push	ax
	mov	ax, [bp-2]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	add	ax, 6
	mov	bx, ax
	mov	ax, [bx]
	pop	bx
	mov	[bx], ax
; RPN'ized expression: "heap next + *u &u free -> *u 1 = "
; Expanded expression: "heap (@-2) *(2) 10 * + 4 + 1 =(1) "
; Fused expression:    "* *(@-2) 10 + heap ax + ax 4 =(154) *ax 1 "
	mov	ax, [bp-2]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	add	ax, 4
	mov	bx, ax
	mov	ax, 1
	mov	[bx], al
	mov	ah, 0
; RPN'ized expression: "heap next + *u &u used -> *u 0 = "
; Expanded expression: "heap (@-2) *(2) 10 * + 8 + 0 =(1) "
; Fused expression:    "* *(@-2) 10 + heap ax + ax 8 =(154) *ax 0 "
	mov	ax, [bp-2]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	add	ax, 8
	mov	bx, ax
	mov	ax, 0
	mov	[bx], al
	mov	ah, 0
; }
L34:
L32:
	leave
	ret

; glb ptr_from_block : (
; prm     idx : int
;     ) * void
section .text
	global	_ptr_from_block
_ptr_from_block:
	push	bp
	mov	bp, sp
	;sub	sp,          0
; loc     idx : (@4) : int
; return
; RPN'ized expression: "memory_pool heap idx + *u &u start -> *u + *u &u "
; Expanded expression: "memory_pool *(2) heap (@4) *(2) 10 * + 0 + *(2) + "
; Fused expression:    "* *(@4) 10 + heap ax + ax 0 + *memory_pool *ax  "
	mov	ax, [bp+4]
	imul	ax, ax, 10
	mov	cx, ax
	mov	ax, _heap
	add	ax, cx
	mov	bx, ax
	mov	cx, [bx]
	mov	ax, [_memory_pool]
	add	ax, cx
L37:
	leave
	ret

; glb putchar : (
; prm     c : char
;     ) void
section .text
	global	_putchar
_putchar:
	push	bp
	mov	bp, sp
	;sub	sp,          0
; loc     c : (@4) : char
mov al,[bp+4]
mov ah,0x0e
int 0x10
int 14h
L39:
	leave
	ret

; glb print_hex_byte : (
; prm     value : unsigned char
;     ) void
section .text
	global	_print_hex_byte
_print_hex_byte:
	push	bp
	mov	bp, sp
	 sub	sp,          2
; loc     value : (@4) : unsigned char
; loc     n : (@-2) : unsigned char
; RPN'ized expression: "n value 4 >> = "
; Expanded expression: "(@-2) (@4) *(1) 4 >> =(1) "
; Fused expression:    ">> *(@4) 4 =(154) *(@-2) ax "
	mov	al, [bp+4]
	mov	ah, 0
	sar	ax, 4
	mov	[bp-2], al
	mov	ah, 0
; if
; RPN'ized expression: "n 10 < "
; Expanded expression: "(@-2) *(1) 10 < "
; Fused expression:    "< *(@-2) 10 IF! "
	mov	al, [bp-2]
	mov	ah, 0
	cmp	ax, 10
	jge	L43
; RPN'ized expression: "n 48 += "
; Expanded expression: "(@-2) 48 +=(1) "
; Fused expression:    "+=(154) *(@-2) 48 "
	mov	al, [bp-2]
	mov	ah, 0
	add	ax, 48
	mov	[bp-2], al
	mov	ah, 0
	jmp	L44
L43:
; else
; RPN'ized expression: "n 65 10 - += "
; Expanded expression: "(@-2) 55 +=(1) "
; Fused expression:    "+=(154) *(@-2) 55 "
	mov	al, [bp-2]
	mov	ah, 0
	add	ax, 55
	mov	[bp-2], al
	mov	ah, 0
L44:
; RPN'ized expression: "( n putchar ) "
; Expanded expression: " (@-2) *(1)  putchar ()2 "
; Fused expression:    "( *(1) (@-2) , putchar )2 "
	mov	al, [bp-2]
	mov	ah, 0
	push	ax
	call	_putchar
	sub	sp, -2
; RPN'ized expression: "n value 15 & = "
; Expanded expression: "(@-2) (@4) *(1) 15 & =(1) "
; Fused expression:    "& *(@4) 15 =(154) *(@-2) ax "
	mov	al, [bp+4]
	mov	ah, 0
	and	ax, 15
	mov	[bp-2], al
	mov	ah, 0
; if
; RPN'ized expression: "n 10 < "
; Expanded expression: "(@-2) *(1) 10 < "
; Fused expression:    "< *(@-2) 10 IF! "
	mov	al, [bp-2]
	mov	ah, 0
	cmp	ax, 10
	jge	L45
; RPN'ized expression: "n 48 += "
; Expanded expression: "(@-2) 48 +=(1) "
; Fused expression:    "+=(154) *(@-2) 48 "
	mov	al, [bp-2]
	mov	ah, 0
	add	ax, 48
	mov	[bp-2], al
	mov	ah, 0
	jmp	L46
L45:
; else
; RPN'ized expression: "n 65 10 - += "
; Expanded expression: "(@-2) 55 +=(1) "
; Fused expression:    "+=(154) *(@-2) 55 "
	mov	al, [bp-2]
	mov	ah, 0
	add	ax, 55
	mov	[bp-2], al
	mov	ah, 0
L46:
; RPN'ized expression: "( n putchar ) "
; Expanded expression: " (@-2) *(1)  putchar ()2 "
; Fused expression:    "( *(1) (@-2) , putchar )2 "
	mov	al, [bp-2]
	mov	ah, 0
	push	ax
	call	_putchar
	sub	sp, -2
L41:
	leave
	ret

; glb strcmp : (
; prm     s1 : * char
; prm     s2 : * char
;     ) int
section .text
	global	_strcmp
_strcmp:
	push	bp
	mov	bp, sp
	;sub	sp,          0
; loc     s1 : (@4) : * char
; loc     s2 : (@6) : * char
; while
; RPN'ized expression: "s1 *u s2 *u && s1 *u s2 *u == && "
; Expanded expression: "(@4) *(2) *(-1) _Bool [sh&&->52] (@6) *(2) *(-1) _Bool &&[52] _Bool [sh&&->51] (@4) *(2) *(-1) (@6) *(2) *(-1) == &&[51] "
L49:
; Fused expression:    "*(2) (@4) *(-1) ax _Bool [sh&&->52] *(2) (@6) *(-1) ax _Bool &&[52] _Bool [sh&&->51] *(2) (@4) push-ax *(2) (@6) == **sp *ax &&[51]  "
	mov	ax, [bp+4]
	mov	bx, ax
	mov	al, [bx]
	cbw
	test	ax, ax
	setne	al
	cbw
; JumpIfZero
	test	ax, ax
	je	L52
	mov	ax, [bp+6]
	mov	bx, ax
	mov	al, [bx]
	cbw
	test	ax, ax
	setne	al
	cbw
L52:
	test	ax, ax
	setne	al
	cbw
; JumpIfZero
	test	ax, ax
	je	L51
	mov	ax, [bp+4]
	push	ax
	mov	ax, [bp+6]
	mov	bx, ax
	movsx	cx, byte [bx]
	pop	bx
	mov	al, [bx]
	cbw
	cmp	ax, cx
	sete	al
	cbw
L51:
; JumpIfZero
	test	ax, ax
	je	L50
; {
; RPN'ized expression: "s1 ++p "
; Expanded expression: "(@4) ++p(2) "
; Fused expression:    "++p(2) *(@4) "
	mov	ax, [bp+4]
	inc	word [bp+4]
; RPN'ized expression: "s2 ++p "
; Expanded expression: "(@6) ++p(2) "
; Fused expression:    "++p(2) *(@6) "
	mov	ax, [bp+6]
	inc	word [bp+6]
; }
	jmp	L49
L50:
; return
; RPN'ized expression: "s1 *u s2 *u - "
; Expanded expression: "(@4) *(2) *(-1) (@6) *(2) *(-1) - "
; Fused expression:    "*(2) (@4) push-ax *(2) (@6) - **sp *ax  "
	mov	ax, [bp+4]
	push	ax
	mov	ax, [bp+6]
	mov	bx, ax
	movsx	cx, byte [bx]
	pop	bx
	mov	al, [bx]
	cbw
	sub	ax, cx
L47:
	leave
	ret

; glb print : (
; prm     s : * char
;     ) void
section .text
	global	_print
_print:
	push	bp
	mov	bp, sp
	;sub	sp,          0
; loc     s : (@4) : * char
; while
; RPN'ized expression: "s *u "
; Expanded expression: "(@4) *(2) *(-1) "
L55:
; Fused expression:    "*(2) (@4) *(-1) ax  "
	mov	ax, [bp+4]
	mov	bx, ax
	mov	al, [bx]
	cbw
; JumpIfZero
	test	ax, ax
	je	L56
; {
; RPN'ized expression: "( s *u putchar ) "
; Expanded expression: " (@4) *(2) *(-1)  putchar ()2 "
; Fused expression:    "( *(2) (@4) *(-1) ax , putchar )2 "
	mov	ax, [bp+4]
	mov	bx, ax
	mov	al, [bx]
	cbw
	push	ax
	call	_putchar
	sub	sp, -2
; RPN'ized expression: "s ++p "
; Expanded expression: "(@4) ++p(2) "
; Fused expression:    "++p(2) *(@4) "
	mov	ax, [bp+4]
	inc	word [bp+4]
; }
	jmp	L55
L56:
L53:
	leave
	ret

; glb reboot : () void
section .text
	global	_reboot
_reboot:
	push	bp
	mov	bp, sp
	;sub	sp,          0
mov al, 0xFE
out 0x64, al
L57:
	leave
	ret

; glb print_hex : (
; prm     s : * char
;     ) void
section .text
	global	_print_hex
_print_hex:
	push	bp
	mov	bp, sp
	;sub	sp,          0
; loc     s : (@4) : * char
; while
; RPN'ized expression: "s *u "
; Expanded expression: "(@4) *(2) *(-1) "
L61:
; Fused expression:    "*(2) (@4) *(-1) ax  "
	mov	ax, [bp+4]
	mov	bx, ax
	mov	al, [bx]
	cbw
; JumpIfZero
	test	ax, ax
	je	L62
; {
; RPN'ized expression: "( s *u print_hex_byte ) "
; Expanded expression: " (@4) *(2) *(-1)  print_hex_byte ()2 "
; Fused expression:    "( *(2) (@4) *(-1) ax , print_hex_byte )2 "
	mov	ax, [bp+4]
	mov	bx, ax
	mov	al, [bx]
	cbw
	push	ax
	call	_print_hex_byte
	sub	sp, -2
; RPN'ized expression: "s ++p "
; Expanded expression: "(@4) ++p(2) "
; Fused expression:    "++p(2) *(@4) "
	mov	ax, [bp+4]
	inc	word [bp+4]
; }
	jmp	L61
L62:
L59:
	leave
	ret

; glb clear_screen : () void
section .text
	global	_clear_screen
_clear_screen:
	push	bp
	mov	bp, sp
	;sub	sp,          0
mov ah,0x06
mov al,0
mov bh,0x07
mov cx,0
mov dx,0x184f
int 0x10
mov ah,0x02
mov bh,0
mov dh,0
mov dl,0
int 0x10
L63:
	leave
	ret

; glb prompt : () void
section .text
	global	_prompt
_prompt:
	push	bp
	mov	bp, sp
	;sub	sp,          0
; RPN'ized expression: "( CURSOR print ) "
; Expanded expression: " CURSOR  print ()2 "
; Fused expression:    "( CURSOR , print )2 "
	push	_CURSOR
	call	_print
	sub	sp, -2
L65:
	leave
	ret

; glb rand : () unsigned
section .text
	global	_rand
_rand:
	push	bp
	mov	bp, sp
	;sub	sp,          0
; RPN'ized expression: "random random 109 * = "
; Expanded expression: "random random *(2) 109 * =(2) "
; Fused expression:    "* *random 109 =(170) *random ax "
	mov	ax, [_random]
	imul	ax, ax, 109
	mov	[_random], ax
; RPN'ized expression: "random random 1021 + = "
; Expanded expression: "random random *(2) 1021 + =(2) "
; Fused expression:    "+ *random 1021 =(170) *random ax "
	mov	ax, [_random]
	add	ax, 1021
	mov	[_random], ax
; RPN'ized expression: "random random 32749 % = "
; Expanded expression: "random random *(2) 32749 %u =(2) "
; Fused expression:    "%u *random 32749 =(170) *random ax "
	mov	ax, [_random]
	mov	dx, 0
	mov	cx, 32749
	div	cx
	mov	ax, dx
	mov	[_random], ax
; return
; RPN'ized expression: "random "
; Expanded expression: "random *(2) "
; Fused expression:    "*(2) random  "
	mov	ax, [_random]
L67:
	leave
	ret

; glb getchar : () char
section .text
	global	_getchar
_getchar:
	push	bp
	mov	bp, sp
	;sub	sp,          0
xor ah,ah
int 0x16
L69:
	leave
	ret

; glb readline : (
; prm     buf : * char
;     ) void
section .text
	global	_readline
_readline:
	push	bp
	mov	bp, sp
	 sub	sp,          4
; loc     buf : (@4) : * char
; loc     c : (@-2) : char
; loc     i : (@-4) : int
; RPN'ized expression: "i 0 = "
; Expanded expression: "(@-4) 0 =(2) "
; Fused expression:    "=(170) *(@-4) 0 "
	mov	ax, 0
	mov	[bp-4], ax
; for
L73:
; {
; RPN'ized expression: "c ( getchar ) = "
; Expanded expression: "(@-2)  getchar ()0 =(-1) "
; Fused expression:    "( getchar )0 =(122) *(@-2) ax "
	call	_getchar
	mov	[bp-2], al
	cbw
; if
; RPN'ized expression: "c 13 == "
; Expanded expression: "(@-2) *(-1) 13 == "
; Fused expression:    "== *(@-2) 13 IF! "
	mov	al, [bp-2]
	cbw
	cmp	ax, 13
	jne	L77
; {
; RPN'ized expression: "( 13 putchar ) "
; Expanded expression: " 13  putchar ()2 "
; Fused expression:    "( 13 , putchar )2 "
	push	13
	call	_putchar
	sub	sp, -2
; RPN'ized expression: "( 10 putchar ) "
; Expanded expression: " 10  putchar ()2 "
; Fused expression:    "( 10 , putchar )2 "
	push	10
	call	_putchar
	sub	sp, -2
; break
	jmp	L76
; }
L77:
; if
; RPN'ized expression: "c 8 == c 127 == || "
; Expanded expression: "(@-2) *(-1) 8 == [sh||->81] (@-2) *(-1) 127 == ||[81] "
; Fused expression:    "== *(@-2) 8 [sh||->81] == *(@-2) 127 ||[81]  "
	mov	al, [bp-2]
	cbw
	cmp	ax, 8
	sete	al
	cbw
; JumpIfNotZero
	test	ax, ax
	jne	L81
	mov	al, [bp-2]
	cbw
	cmp	ax, 127
	sete	al
	cbw
L81:
; JumpIfZero
	test	ax, ax
	je	L79
; {
; if
; RPN'ized expression: "i 0 > "
; Expanded expression: "(@-4) *(2) 0 > "
; Fused expression:    "> *(@-4) 0 IF! "
	mov	ax, [bp-4]
	cmp	ax, 0
	jle	L82
; {
; RPN'ized expression: "( 8 putchar ) "
; Expanded expression: " 8  putchar ()2 "
; Fused expression:    "( 8 , putchar )2 "
	push	8
	call	_putchar
	sub	sp, -2
; RPN'ized expression: "( 32 putchar ) "
; Expanded expression: " 32  putchar ()2 "
; Fused expression:    "( 32 , putchar )2 "
	push	32
	call	_putchar
	sub	sp, -2
; RPN'ized expression: "( 8 putchar ) "
; Expanded expression: " 8  putchar ()2 "
; Fused expression:    "( 8 , putchar )2 "
	push	8
	call	_putchar
	sub	sp, -2
; RPN'ized expression: "i --p "
; Expanded expression: "(@-4) --p(2) "
; Fused expression:    "--p(2) *(@-4) "
	mov	ax, [bp-4]
	dec	word [bp-4]
; }
L82:
; }
	jmp	L80
L79:
; else
; {
; if
; RPN'ized expression: "i 255 < "
; Expanded expression: "(@-4) *(2) 255 < "
; Fused expression:    "< *(@-4) 255 IF! "
	mov	ax, [bp-4]
	cmp	ax, 255
	jge	L84
; {
; RPN'ized expression: "( c putchar ) "
; Expanded expression: " (@-2) *(-1)  putchar ()2 "
; Fused expression:    "( *(-1) (@-2) , putchar )2 "
	mov	al, [bp-2]
	cbw
	push	ax
	call	_putchar
	sub	sp, -2
; RPN'ized expression: "buf i ++p + *u c = "
; Expanded expression: "(@4) *(2) (@-4) ++p(2) + (@-2) *(-1) =(-1) "
; Fused expression:    "++p(2) *(@-4) + *(@4) ax =(119) *ax *(@-2) "
	mov	ax, [bp-4]
	inc	word [bp-4]
	mov	cx, ax
	mov	ax, [bp+4]
	add	ax, cx
	mov	bx, ax
	mov	al, [bp-2]
	cbw
	mov	[bx], al
	cbw
; }
L84:
; }
L80:
; }
	jmp	L73
L76:
; RPN'ized expression: "buf i + *u 0 = "
; Expanded expression: "(@4) *(2) (@-4) *(2) + 0 =(-1) "
; Fused expression:    "+ *(@4) *(@-4) =(122) *ax 0 "
	mov	ax, [bp+4]
	add	ax, [bp-4]
	mov	bx, ax
	mov	ax, 0
	mov	[bx], al
	cbw
L71:
	leave
	ret

; glb cmd_memory_test : () void
section .text
	global	_cmd_memory_test
_cmd_memory_test:
	push	bp
	mov	bp, sp
	 sub	sp,         10
; loc     block : (@-2) : int
; RPN'ized expression: "block ( 32767 alloc ) = "
; Expanded expression: "(@-2)  32767  alloc ()2 =(2) "
; Fused expression:    "( 32767 , alloc )2 =(170) *(@-2) ax "
	push	32767
	call	_alloc
	sub	sp, -2
	mov	[bp-2], ax
; if
; RPN'ized expression: "block 0 < "
; Expanded expression: "(@-2) *(2) 0 < "
; Fused expression:    "< *(@-2) 0 IF! "
	mov	ax, [bp-2]
	cmp	ax, 0
	jge	L88
; {

section .rodata
L90:
	db	"alloc failed",13,10
	times	1 db 0

section .text
; RPN'ized expression: "( L90 print ) "
; Expanded expression: " L90  print ()2 "
; Fused expression:    "( L90 , print )2 "
	push	L90
	call	_print
	sub	sp, -2
; return
	jmp	L86
; }
L88:
; loc     test_pattern : (@-4) : unsigned char
; RPN'ized expression: "test_pattern 170 = "
; Expanded expression: "(@-4) 170 =(1) "
; Fused expression:    "=(170) *(@-4) 170 "
	mov	ax, 170
	mov	[bp-4], ax
; loc     memory_to_test : (@-6) : * unsigned char
; RPN'ized expression: "memory_to_test ( block ptr_from_block ) = "
; Expanded expression: "(@-6)  (@-2) *(2)  ptr_from_block ()2 =(2) "
; Fused expression:    "( *(2) (@-2) , ptr_from_block )2 =(170) *(@-6) ax "
	push	word [bp-2]
	call	_ptr_from_block
	sub	sp, -2
	mov	[bp-6], ax
; loc     failure : (@-8) : unsigned char
; RPN'ized expression: "failure 0 = "
; Expanded expression: "(@-8) 0 =(1) "
; Fused expression:    "=(170) *(@-8) 0 "
	mov	ax, 0
	mov	[bp-8], ax
; RPN'ized expression: "( memory_to_test print_hex_word ) "
; Expanded expression: " (@-6) *(2)  print_hex_word ()2 "
; Fused expression:    "( *(2) (@-6) , print_hex_word )2 "
	push	word [bp-6]
	call	_print_hex_word
	sub	sp, -2

section .rodata
L91:
	db	13,10
	times	1 db 0

section .text
; RPN'ized expression: "( L91 print ) "
; Expanded expression: " L91  print ()2 "
; Fused expression:    "( L91 , print )2 "
	push	L91
	call	_print
	sub	sp, -2
; for
; loc     i : (@-10) : int
; RPN'ized expression: "i 0 = "
; Expanded expression: "(@-10) 0 =(2) "
; Fused expression:    "=(170) *(@-10) 0 "
	mov	ax, 0
	mov	[bp-10], ax
L92:
; RPN'ized expression: "i 32767 < "
; Expanded expression: "(@-10) *(2) 32767 < "
; Fused expression:    "< *(@-10) 32767 IF! "
	mov	ax, [bp-10]
	cmp	ax, 32767
	jge	L95
; RPN'ized expression: "i ++p "
; Expanded expression: "(@-10) ++p(2) "
; {
; RPN'ized expression: "memory_to_test i + *u test_pattern = "
; Expanded expression: "(@-6) *(2) (@-10) *(2) + (@-4) *(1) =(1) "
; Fused expression:    "+ *(@-6) *(@-10) =(153) *ax *(@-4) "
	mov	ax, [bp-6]
	add	ax, [bp-10]
	mov	bx, ax
	mov	al, [bp-4]
	mov	ah, 0
	mov	[bx], al
	mov	ah, 0
; }
L93:
; Fused expression:    "++p(2) *(@-10) "
	mov	ax, [bp-10]
	inc	word [bp-10]
	jmp	L92
L95:

section .rodata
L96:
	db	"Set memory to test pattern - Testing",13,10
	times	1 db 0

section .text
; RPN'ized expression: "( L96 print ) "
; Expanded expression: " L96  print ()2 "
; Fused expression:    "( L96 , print )2 "
	push	L96
	call	_print
	sub	sp, -2
; for
; loc     i : (@-10) : int
; RPN'ized expression: "i 0 = "
; Expanded expression: "(@-10) 0 =(2) "
; Fused expression:    "=(170) *(@-10) 0 "
	mov	ax, 0
	mov	[bp-10], ax
L97:
; RPN'ized expression: "i 32767 < "
; Expanded expression: "(@-10) *(2) 32767 < "
; Fused expression:    "< *(@-10) 32767 IF! "
	mov	ax, [bp-10]
	cmp	ax, 32767
	jge	L100
; RPN'ized expression: "i ++p "
; Expanded expression: "(@-10) ++p(2) "
; {
; if
; RPN'ized expression: "memory_to_test i + *u test_pattern != "
; Expanded expression: "(@-6) *(2) (@-10) *(2) + *(1) (@-4) *(1) != "
; Fused expression:    "+ *(@-6) *(@-10) != *ax *(@-4) IF! "
	mov	ax, [bp-6]
	add	ax, [bp-10]
	mov	bx, ax
	mov	al, [bx]
	mov	ah, 0
	movzx	cx, byte [bp-4]
	cmp	ax, cx
	je	L101
; {

section .rodata
L103:
	db	"Byte "
	times	1 db 0

section .text
; RPN'ized expression: "( L103 print ) "
; Expanded expression: " L103  print ()2 "
; Fused expression:    "( L103 , print )2 "
	push	L103
	call	_print
	sub	sp, -2
; RPN'ized expression: "( i print_hex_word ) "
; Expanded expression: " (@-10) *(2)  print_hex_word ()2 "
; Fused expression:    "( *(2) (@-10) , print_hex_word )2 "
	push	word [bp-10]
	call	_print_hex_word
	sub	sp, -2

section .rodata
L104:
	db	" failed validation",13,10
	times	1 db 0

section .text
; RPN'ized expression: "( L104 print ) "
; Expanded expression: " L104  print ()2 "
; Fused expression:    "( L104 , print )2 "
	push	L104
	call	_print
	sub	sp, -2
; RPN'ized expression: "failure 1 = "
; Expanded expression: "(@-8) 1 =(1) "
; Fused expression:    "=(154) *(@-8) 1 "
	mov	ax, 1
	mov	[bp-8], al
	mov	ah, 0

section .rodata
L105:
	db	"Expected: "
	times	1 db 0

section .text
; RPN'ized expression: "( L105 print ) "
; Expanded expression: " L105  print ()2 "
; Fused expression:    "( L105 , print )2 "
	push	L105
	call	_print
	sub	sp, -2
; RPN'ized expression: "( test_pattern print_hex_word ) "
; Expanded expression: " (@-4) *(1)  print_hex_word ()2 "
; Fused expression:    "( *(1) (@-4) , print_hex_word )2 "
	mov	al, [bp-4]
	mov	ah, 0
	push	ax
	call	_print_hex_word
	sub	sp, -2

section .rodata
L106:
	db	" got: "
	times	1 db 0

section .text
; RPN'ized expression: "( L106 print ) "
; Expanded expression: " L106  print ()2 "
; Fused expression:    "( L106 , print )2 "
	push	L106
	call	_print
	sub	sp, -2
; RPN'ized expression: "( memory_to_test i + *u print_hex_word ) "
; Expanded expression: " (@-6) *(2) (@-10) *(2) + *(1)  print_hex_word ()2 "
; Fused expression:    "( + *(@-6) *(@-10) *(1) ax , print_hex_word )2 "
	mov	ax, [bp-6]
	add	ax, [bp-10]
	mov	bx, ax
	mov	al, [bx]
	mov	ah, 0
	push	ax
	call	_print_hex_word
	sub	sp, -2

section .rodata
L107:
	db	" Address: "
	times	1 db 0

section .text
; RPN'ized expression: "( L107 print ) "
; Expanded expression: " L107  print ()2 "
; Fused expression:    "( L107 , print )2 "
	push	L107
	call	_print
	sub	sp, -2
; loc             <something> : unsigned
; RPN'ized expression: "( memory_to_test i + *u &u (something108) print_hex_word ) "
; Expanded expression: " (@-6) *(2) (@-10) *(2) +  print_hex_word ()2 "
; Fused expression:    "( + *(@-6) *(@-10) , print_hex_word )2 "
	mov	ax, [bp-6]
	add	ax, [bp-10]
	push	ax
	call	_print_hex_word
	sub	sp, -2

section .rodata
L109:
	db	13,10
	times	1 db 0

section .text
; RPN'ized expression: "( L109 print ) "
; Expanded expression: " L109  print ()2 "
; Fused expression:    "( L109 , print )2 "
	push	L109
	call	_print
	sub	sp, -2
; }
L101:
; if
; RPN'ized expression: "i 1024 % 0 == "
; Expanded expression: "(@-10) *(2) 1024 % 0 == "
; Fused expression:    "% *(@-10) 1024 == ax 0 IF! "
	mov	ax, [bp-10]
	cwd
	mov	cx, 1024
	idiv	cx
	mov	ax, dx
	cmp	ax, 0
	jne	L110
; {
; RPN'ized expression: "( i 1024 / print_dec ) "
; Expanded expression: " (@-10) *(2) 1024 /  print_dec ()2 "
; Fused expression:    "( / *(@-10) 1024 , print_dec )2 "
	mov	ax, [bp-10]
	cwd
	mov	cx, 1024
	idiv	cx
	push	ax
	call	_print_dec
	sub	sp, -2

section .rodata
L112:
	db	" | "
	times	1 db 0

section .text
; RPN'ized expression: "( L112 print ) "
; Expanded expression: " L112  print ()2 "
; Fused expression:    "( L112 , print )2 "
	push	L112
	call	_print
	sub	sp, -2
; }
L110:
; }
L98:
; Fused expression:    "++p(2) *(@-10) "
	mov	ax, [bp-10]
	inc	word [bp-10]
	jmp	L97
L100:
; if
; RPN'ized expression: "failure 1 == "
; Expanded expression: "(@-8) *(1) 1 == "
; Fused expression:    "== *(@-8) 1 IF! "
	mov	al, [bp-8]
	mov	ah, 0
	cmp	ax, 1
	jne	L113
; {

section .rodata
L115:
	db	13,10,"Some memory failed test.",13,10
	times	1 db 0

section .text
; RPN'ized expression: "( L115 print ) "
; Expanded expression: " L115  print ()2 "
; Fused expression:    "( L115 , print )2 "
	push	L115
	call	_print
	sub	sp, -2
; }
L113:
; RPN'ized expression: "( block free_block ) "
; Expanded expression: " (@-2) *(2)  free_block ()2 "
; Fused expression:    "( *(2) (@-2) , free_block )2 "
	push	word [bp-2]
	call	_free_block
	sub	sp, -2

section .rodata
L116:
	db	"Memory test complete",13,10
	times	1 db 0

section .text
; RPN'ized expression: "( L116 print ) "
; Expanded expression: " L116  print ()2 "
; Fused expression:    "( L116 , print )2 "
	push	L116
	call	_print
	sub	sp, -2
L86:
	leave
	ret

; glb print_dec : (
; prm     v : unsigned
;     ) void
section .text
	global	_print_dec
_print_dec:
	push	bp
	mov	bp, sp
	 sub	sp,         12
; loc     v : (@4) : unsigned
; RPN'ized expression: "10 "
; Expanded expression: "10 "
; Expression value: 10
; loc     buf : (@-10) : [10u] char
; loc     i : (@-12) : int
; RPN'ized expression: "i 0 = "
; Expanded expression: "(@-12) 0 =(2) "
; Fused expression:    "=(170) *(@-12) 0 "
	mov	ax, 0
	mov	[bp-12], ax
; if
; RPN'ized expression: "v 0 == "
; Expanded expression: "(@4) *(2) 0 == "
; Fused expression:    "== *(@4) 0 IF! "
	mov	ax, [bp+4]
	cmp	ax, 0
	jne	L119
; {
; RPN'ized expression: "( 48 putchar ) "
; Expanded expression: " 48  putchar ()2 "
; Fused expression:    "( 48 , putchar )2 "
	push	48
	call	_putchar
	sub	sp, -2
; return
	jmp	L117
; }
L119:
; while
; RPN'ized expression: "v 0 > "
; Expanded expression: "(@4) *(2) 0 >u "
L121:
; Fused expression:    ">u *(@4) 0 IF! "
	mov	ax, [bp+4]
	cmp	ax, 0
	jbe	L122
; {
; RPN'ized expression: "buf i ++p + *u 48 v 10 % + = "
; Expanded expression: "(@-10) (@-12) ++p(2) + 48 (@4) *(2) 10 %u + =(-1) "
; Fused expression:    "++p(2) *(@-12) + (@-10) ax push-ax %u *(@4) 10 + 48 ax =(122) **sp ax "
	mov	ax, [bp-12]
	inc	word [bp-12]
	mov	cx, ax
	lea	ax, [bp-10]
	add	ax, cx
	push	ax
	mov	ax, [bp+4]
	mov	dx, 0
	mov	cx, 10
	div	cx
	mov	ax, dx
	mov	cx, ax
	mov	ax, 48
	add	ax, cx
	pop	bx
	mov	[bx], al
	cbw
; RPN'ized expression: "v 10 /= "
; Expanded expression: "(@4) 10 /=u(2) "
; Fused expression:    "/=u(170) *(@4) 10 "
	mov	ax, [bp+4]
	mov	dx, 0
	mov	cx, 10
	div	cx
	mov	[bp+4], ax
; }
	jmp	L121
L122:
; while
; RPN'ized expression: "i --p "
; Expanded expression: "(@-12) --p(2) "
L123:
; Fused expression:    "--p(2) *(@-12)  "
	mov	ax, [bp-12]
	dec	word [bp-12]
; JumpIfZero
	test	ax, ax
	je	L124
; {
; RPN'ized expression: "( buf i + *u putchar ) "
; Expanded expression: " (@-10) (@-12) *(2) + *(-1)  putchar ()2 "
; Fused expression:    "( + (@-10) *(@-12) *(-1) ax , putchar )2 "
	lea	ax, [bp-10]
	add	ax, [bp-12]
	mov	bx, ax
	mov	al, [bx]
	cbw
	push	ax
	call	_putchar
	sub	sp, -2
; }
	jmp	L123
L124:
L117:
	leave
	ret

; glb print_hex_word : (
; prm     value : unsigned
;     ) void
section .text
	global	_print_hex_word
_print_hex_word:
	push	bp
	mov	bp, sp
	;sub	sp,          0
; loc     value : (@4) : unsigned
; RPN'ized expression: "( value 8 >> 255 & print_hex_byte ) "
; Expanded expression: " (@4) *(2) 8 >>u 255 &  print_hex_byte ()2 "
; Fused expression:    "( >>u *(@4) 8 & ax 255 , print_hex_byte )2 "
	mov	ax, [bp+4]
	shr	ax, 8
	and	ax, 255
	push	ax
	call	_print_hex_byte
	sub	sp, -2
; RPN'ized expression: "( value 255 & print_hex_byte ) "
; Expanded expression: " (@4) *(2) 255 &  print_hex_byte ()2 "
; Fused expression:    "( & *(@4) 255 , print_hex_byte )2 "
	mov	ax, [bp+4]
	and	ax, 255
	push	ax
	call	_print_hex_byte
	sub	sp, -2
L125:
	leave
	ret

; glb print_memory : () void
section .text
	global	_print_memory
_print_memory:
	push	bp
	mov	bp, sp
	;sub	sp,          0

section .rodata
L129:
	db	"Memory: "
	times	1 db 0

section .text
; RPN'ized expression: "( L129 print ) "
; Expanded expression: " L129  print ()2 "
; Fused expression:    "( L129 , print )2 "
	push	L129
	call	_print
	sub	sp, -2
; RPN'ized expression: "( ( get_memory_kb ) print_dec ) "
; Expanded expression: "  get_memory_kb ()0  print_dec ()2 "
; Fused expression:    "( ( get_memory_kb )0 , print_dec )2 "
	call	_get_memory_kb
	push	ax
	call	_print_dec
	sub	sp, -2

section .rodata
L130:
	db	"KB RAM"
	times	1 db 0

section .text
; RPN'ized expression: "( L130 print ) "
; Expanded expression: " L130  print ()2 "
; Fused expression:    "( L130 , print )2 "
	push	L130
	call	_print
	sub	sp, -2
L127:
	leave
	ret

; glb read_to_string : (
; prm     file : char
;     ) char
section .text
	global	_read_to_string
_read_to_string:
	push	bp
	mov	bp, sp
	;sub	sp,          0
; loc     file : (@4) : char
L131:
	leave
	ret

; glb terminal : () void
section .text
	global	_terminal
_terminal:
	push	bp
	mov	bp, sp
	 sub	sp,        258
; RPN'ized expression: "256 "
; Expanded expression: "256 "
; Expression value: 256
; loc     buf : (@-256) : [256u] char
; loc     commands : (@-258) : struct cmds
; for
L135:
; {
; RPN'ized expression: "( prompt ) "
; Expanded expression: " prompt ()0 "
; Fused expression:    "( prompt )0 "
	call	_prompt
; RPN'ized expression: "( buf readline ) "
; Expanded expression: " (@-256)  readline ()2 "
; Fused expression:    "( (@-256) , readline )2 "
	lea	ax, [bp-256]
	push	ax
	call	_readline
	sub	sp, -2
; if

section .rodata
L141:
	db	"ver"
	times	1 db 0

section .text
; RPN'ized expression: "( L141 , buf strcmp ) 0 == "
; Expanded expression: " L141  (@-256)  strcmp ()4 0 == "
; Fused expression:    "( L141 , (@-256) , strcmp )4 == ax 0 IF! "
	push	L141
	lea	ax, [bp-256]
	push	ax
	call	_strcmp
	sub	sp, -4
	cmp	ax, 0
	jne	L139
; {

section .rodata
L142:
	db	"Indev crap, yay. This'll *eventually* return the hash of the source code or a version or something somehow."
	times	1 db 0

section .text
; RPN'ized expression: "( L142 print ) "
; Expanded expression: " L142  print ()2 "
; Fused expression:    "( L142 , print )2 "
	push	L142
	call	_print
	sub	sp, -2
; }
	jmp	L140
L139:
; else
; if

section .rodata
L145:
	db	"test"
	times	1 db 0

section .text
; RPN'ized expression: "( L145 , buf strcmp ) 0 == "
; Expanded expression: " L145  (@-256)  strcmp ()4 0 == "
; Fused expression:    "( L145 , (@-256) , strcmp )4 == ax 0 IF! "
	push	L145
	lea	ax, [bp-256]
	push	ax
	call	_strcmp
	sub	sp, -4
	cmp	ax, 0
	jne	L143
; {

section .rodata
L146:
	db	"test returned"
	times	1 db 0

section .text
; RPN'ized expression: "( L146 print ) "
; Expanded expression: " L146  print ()2 "
; Fused expression:    "( L146 , print )2 "
	push	L146
	call	_print
	sub	sp, -2
; }
	jmp	L144
L143:
; else
; if

section .rodata
L149:
	db	"clear"
	times	1 db 0

section .text
; RPN'ized expression: "( L149 , buf strcmp ) 0 == "
; Expanded expression: " L149  (@-256)  strcmp ()4 0 == "
; Fused expression:    "( L149 , (@-256) , strcmp )4 == ax 0 IF! "
	push	L149
	lea	ax, [bp-256]
	push	ax
	call	_strcmp
	sub	sp, -4
	cmp	ax, 0
	jne	L147
; {
; RPN'ized expression: "( clear_screen ) "
; Expanded expression: " clear_screen ()0 "
; Fused expression:    "( clear_screen )0 "
	call	_clear_screen
; }
	jmp	L148
L147:
; else
; if

section .rodata
L152:
	db	"memsize"
	times	1 db 0

section .text
; RPN'ized expression: "( L152 , buf strcmp ) 0 == "
; Expanded expression: " L152  (@-256)  strcmp ()4 0 == "
; Fused expression:    "( L152 , (@-256) , strcmp )4 == ax 0 IF! "
	push	L152
	lea	ax, [bp-256]
	push	ax
	call	_strcmp
	sub	sp, -4
	cmp	ax, 0
	jne	L150
; {
; RPN'ized expression: "( print_memory ) "
; Expanded expression: " print_memory ()0 "
; Fused expression:    "( print_memory )0 "
	call	_print_memory
; }
	jmp	L151
L150:
; else
; if

section .rodata
L155:
	db	"fuck"
	times	1 db 0

section .text
; RPN'ized expression: "( L155 , buf strcmp ) 0 == "
; Expanded expression: " L155  (@-256)  strcmp ()4 0 == "
; Fused expression:    "( L155 , (@-256) , strcmp )4 == ax 0 IF! "
	push	L155
	lea	ax, [bp-256]
	push	ax
	call	_strcmp
	sub	sp, -4
	cmp	ax, 0
	jne	L153
; {
; RPN'ized expression: "( reboot ) "
; Expanded expression: " reboot ()0 "
; Fused expression:    "( reboot )0 "
	call	_reboot
; }
	jmp	L154
L153:
; else
; if

section .rodata
L158:
	db	"memtest"
	times	1 db 0

section .text
; RPN'ized expression: "( L158 , buf strcmp ) 0 == "
; Expanded expression: " L158  (@-256)  strcmp ()4 0 == "
; Fused expression:    "( L158 , (@-256) , strcmp )4 == ax 0 IF! "
	push	L158
	lea	ax, [bp-256]
	push	ax
	call	_strcmp
	sub	sp, -4
	cmp	ax, 0
	jne	L156
; {
; RPN'ized expression: "( cmd_memory_test ) "
; Expanded expression: " cmd_memory_test ()0 "
; Fused expression:    "( cmd_memory_test )0 "
	call	_cmd_memory_test
; }
	jmp	L157
L156:
; else
; if

section .rodata
L161:
	db	"random"
	times	1 db 0

section .text
; RPN'ized expression: "( L161 , buf strcmp ) 0 == "
; Expanded expression: " L161  (@-256)  strcmp ()4 0 == "
; Fused expression:    "( L161 , (@-256) , strcmp )4 == ax 0 IF! "
	push	L161
	lea	ax, [bp-256]
	push	ax
	call	_strcmp
	sub	sp, -4
	cmp	ax, 0
	jne	L159
; {
; RPN'ized expression: "( rand ) "
; Expanded expression: " rand ()0 "
; Fused expression:    "( rand )0 "
	call	_rand
; RPN'ized expression: "( random print_dec ) "
; Expanded expression: " random *(2)  print_dec ()2 "
; Fused expression:    "( *(2) random , print_dec )2 "
	push	word [_random]
	call	_print_dec
	sub	sp, -2
; }
	jmp	L160
L159:
; else
; {

section .rodata
L162:
	db	"Command not found. Buf was "
	times	1 db 0

section .text
; RPN'ized expression: "( L162 print ) "
; Expanded expression: " L162  print ()2 "
; Fused expression:    "( L162 , print )2 "
	push	L162
	call	_print
	sub	sp, -2
; RPN'ized expression: "( buf print ) "
; Expanded expression: " (@-256)  print ()2 "
; Fused expression:    "( (@-256) , print )2 "
	lea	ax, [bp-256]
	push	ax
	call	_print
	sub	sp, -2
; }
L160:
L157:
L154:
L151:
L148:
L144:
L140:

section .rodata
L163:
	db	13,10
	times	1 db 0

section .text
; RPN'ized expression: "( L163 print ) "
; Expanded expression: " L163  print ()2 "
; Fused expression:    "( L163 , print )2 "
	push	L163
	call	_print
	sub	sp, -2
; }
	jmp	L135
L138:
L133:
	leave
	ret

; glb main : () void
section .text
	global	_main
_main:
	push	bp
	mov	bp, sp
	 sub	sp,          2
; loc     msg : (@-2) : * char

section .rodata
L166:
	db	13,10,"Welcome to ZMS!",13,10
	times	1 db 0

section .text
; RPN'ized expression: "msg L166 = "
; Expanded expression: "(@-2) L166 =(2) "
; Fused expression:    "=(170) *(@-2) L166 "
	mov	ax, L166
	mov	[bp-2], ax
; RPN'ized expression: "( msg print ) "
; Expanded expression: " (@-2) *(2)  print ()2 "
; Fused expression:    "( *(2) (@-2) , print )2 "
	push	word [bp-2]
	call	_print
	sub	sp, -2
; RPN'ized expression: "( init_heap ) "
; Expanded expression: " init_heap ()0 "
; Fused expression:    "( init_heap )0 "
	call	_init_heap
; RPN'ized expression: "( terminal ) "
; Expanded expression: " terminal ()0 "
; Fused expression:    "( terminal )0 "
	call	_terminal
; Fused expression:    "0  "
	mov	ax, 0
L164:
	leave
	ret


	extern	_get_memory_kb

; Syntax/declaration table/stack:
; Bytes used: 1135/15360


; Macro table:
; Macro __SMALLER_C__ = `0x0100`
; Macro __SMALLER_C_16__ = ``
; Macro __SMALLER_C_SCHAR__ = ``
; Macro __SMALLER_C_UWCHAR__ = ``
; Macro __SMALLER_C_WCHAR16__ = ``
; Macro MAX_BLOCKS = `64`
; Macro HEAP_START = `0x3000`
; Bytes used: 144/5120


; Identifier table:
; Ident 
; Ident __floatsisf
; Ident __floatunsisf
; Ident __fixsfsi
; Ident __fixunssfsi
; Ident __addsf3
; Ident __subsf3
; Ident __negsf2
; Ident __mulsf3
; Ident __divsf3
; Ident __lesf2
; Ident __gesf2
; Ident CURSOR
; Ident uint16_t
; Ident int16_t
; Ident uint8_t
; Ident random
; Ident cmd
; Ident canonical_name
; Ident executable
; Ident <something>
; Ident cmds
; Ident commands
; Ident mem_block
; Ident start
; Ident size
; Ident free
; Ident next_index
; Ident used
; Ident get_memory_kb
; Ident command_registry
; Ident TOTAL_HEAP_SIZE
; Ident memory_pool
; Ident free_list_head
; Ident heap
; Ident init_heap
; Ident find_block
; Ident find_free_struct_block
; Ident alloc
; Ident free_block
; Ident idx
; Ident ptr_from_block
; Ident putchar
; Ident c
; Ident print_hex_byte
; Ident value
; Ident strcmp
; Ident s1
; Ident s2
; Ident print
; Ident s
; Ident reboot
; Ident print_hex
; Ident clear_screen
; Ident prompt
; Ident rand
; Ident getchar
; Ident readline
; Ident buf
; Ident cmd_memory_test
; Ident print_dec
; Ident v
; Ident print_hex_word
; Ident print_memory
; Ident read_to_string
; Ident file
; Ident terminal
; Ident main
; Bytes used: 680/5632

; Next label number: 167
; Compilation succeeded.
