more work

This commit is contained in:
Emanuel Rodriguez 2023-01-04 21:53:29 -08:00
parent 24aabcf0a0
commit 9eeacd4206
3 changed files with 15 additions and 6 deletions

View File

@ -1,7 +1,7 @@
option casemap:none
; constants
nl = 10 ; newline
nl = 10 ; newline
maxlen = 256 ; max len of the string
.data
@ -17,10 +17,14 @@ input byte maxlen dup (?) ; make maxlen copies of byte, each uninitialized
externdef printf:proc
externdef readline:proc
;; get_title procedure -------------------------
;; get_title moves the address of the byte containing the string "Listing 1_8", 0
;; into the RAX register, it does this usig the LEA instruction
public get_title
get_title proc
lea rax, title_string
lea rax, title_string ; load address of title_string into rax
ret
get_title endp
@ -30,18 +34,21 @@ asm_main proc
sub rsp, 56
; first we want to print a prompt, to do this we use the C++ function printf
; we load this prompt in RCX and then call
;; first we want to print a prompt, to do this we use the stdio function printf,
;; we need to make the arguments for printf avaialble by loading the address of the
;; byte prompt_string into RCX
lea rcx, prompt_string
call printf
mov input, 0
mov input, 0 ;; clear the input
; read user input
; read user input by calling readline from out cpp program. We load the required
; arguments into the registers RCX, and RDX and then call readline
lea rcx, input
mov rdx, maxlen
call readline
; load RCX and RDX with arugments to printf, to print back to the user
lea rcx, format_string
lea rdx, input
call printf

View File

@ -8,6 +8,7 @@ extern "C"
{
void asm_main(void);
// function is defined in the asm file
char *get_title(void);
int readline(char* dest, int maxlen);

1
src/listing_1_9.cpp Normal file
View File

@ -0,0 +1 @@
listing_1_9.cpp