-; prompt for user
-; no args - reads from globals
-repl:
-
- %define CMDSTR 4 ; the previous line read from user
-
- push ebp
- mov ebp, esp
-
- sub esp, 4
-
- _repl_loop:
-
- ; print the prompt
- push prompt_str
- call printf
- push DWORD [stdout]
- call fflush
-
- ; read line from stdin
- push 0
- call readLine
-
- mov DWORD [ebp-CMDSTR], eax
-
- ; commands are single char for now
- cmp ecx, 1
- jne _repl_invalid
-
- ; parse commands
- mov eax, DWORD [ebp-CMDSTR]
- mov eax, [eax]
-
- ; q exists program
- mov eax, DWORD [ebp-CMDSTR]
- cmp BYTE [eax], 'q'
- jne _repl_cmd_quit_end
- jmp _repl_exit
- _repl_cmd_quit_end:
-
-
- _repl_invalid:
- push invalidcommand_str
- call printf
-
- _repl_continue:
- jmp _repl_loop
-
- _repl_exit:
-
- %undef CMDSTR
-
- mov esp, ebp
- pop ebp
- ret
-