diff --git a/src/1_8.asm b/src/1_8.asm index 170cdb6..54d10a5 100644 --- a/src/1_8.asm +++ b/src/1_8.asm @@ -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 diff --git a/src/c.cpp b/src/c.cpp index 83c72da..e4ca6d9 100644 --- a/src/c.cpp +++ b/src/c.cpp @@ -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); diff --git a/src/listing_1_9.cpp b/src/listing_1_9.cpp new file mode 100644 index 0000000..917cebb --- /dev/null +++ b/src/listing_1_9.cpp @@ -0,0 +1 @@ +listing_1_9.cpp \ No newline at end of file