more work
This commit is contained in:
parent
24aabcf0a0
commit
9eeacd4206
19
src/1_8.asm
19
src/1_8.asm
|
@ -1,7 +1,7 @@
|
||||||
option casemap:none
|
option casemap:none
|
||||||
|
|
||||||
; constants
|
; constants
|
||||||
nl = 10 ; newline
|
nl = 10 ; newline
|
||||||
maxlen = 256 ; max len of the string
|
maxlen = 256 ; max len of the string
|
||||||
|
|
||||||
.data
|
.data
|
||||||
|
@ -17,10 +17,14 @@ input byte maxlen dup (?) ; make maxlen copies of byte, each uninitialized
|
||||||
externdef printf:proc
|
externdef printf:proc
|
||||||
externdef readline: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
|
public get_title
|
||||||
get_title proc
|
get_title proc
|
||||||
|
|
||||||
lea rax, title_string
|
lea rax, title_string ; load address of title_string into rax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
get_title endp
|
get_title endp
|
||||||
|
@ -30,18 +34,21 @@ asm_main proc
|
||||||
|
|
||||||
sub rsp, 56
|
sub rsp, 56
|
||||||
|
|
||||||
; first we want to print a prompt, to do this we use the C++ function printf
|
;; first we want to print a prompt, to do this we use the stdio function printf,
|
||||||
; we load this prompt in RCX and then call
|
;; we need to make the arguments for printf avaialble by loading the address of the
|
||||||
|
;; byte prompt_string into RCX
|
||||||
lea rcx, prompt_string
|
lea rcx, prompt_string
|
||||||
call printf
|
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
|
lea rcx, input
|
||||||
mov rdx, maxlen
|
mov rdx, maxlen
|
||||||
call readline
|
call readline
|
||||||
|
|
||||||
|
; load RCX and RDX with arugments to printf, to print back to the user
|
||||||
lea rcx, format_string
|
lea rcx, format_string
|
||||||
lea rdx, input
|
lea rdx, input
|
||||||
call printf
|
call printf
|
||||||
|
|
|
@ -8,6 +8,7 @@ extern "C"
|
||||||
{
|
{
|
||||||
void asm_main(void);
|
void asm_main(void);
|
||||||
|
|
||||||
|
// function is defined in the asm file
|
||||||
char *get_title(void);
|
char *get_title(void);
|
||||||
|
|
||||||
int readline(char* dest, int maxlen);
|
int readline(char* dest, int maxlen);
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
listing_1_9.cpp
|
Loading…
Reference in New Issue