extrn ExitProcess: PROTO
extrn WriteFile: PROTO
extrn ReadFile: PROTO
extrn GetStdHandle: PROTO
mGetHandles MACRO
CONSOLE equ -11
KEYBOARD equ -10
mov rcx, CONSOLE ;subsystem: console
call GetStdHandle ;handle in rax
mov stdout, rax ;save out handle
mov rcx, KEYBOARD ;keyboard code
call GetStdHandle ;handle in rax
mov stdin, rax ;save in handle
ENDM
mWriteConsole MACRO
mov pram, r12b ;moves what is from the first
mov rcx, stdout ;parm1 = console handle
lea rdx, pram ;parm2 = ascii message
mov r8, lengthof pram ;length of what is in pram
lea r9, numWrite ;store number of bits written
mov qword ptr [rsp+32], 0 ;parameter needed for write file
call WriteFile ;display message
ENDM
mReadConsol MACRO
mov input, r12b ;store value from main into input
mov rcx, stdin ;call keybord parm
lea rdx, input ;call input parm
mov r8, lengthof input ;length of input that accepts input
lea r9, numRead ;number of bits read
call ReadFile ;call read keyboard
mov r12b, input ;store input into r12 register to pass back
ENDM
.data
namProm byte 'What is your name? '
addProm byte 'What is your address? '
prompt byte 'Nice to meet you,'
myName byte 40 dup(0),0ah
address byte 40 dup(0),0ah
newLine byte 0ah
.data?
stdin qword ?
stdout qword ?
numWrite qword ?
numRead qword ?
pram byte ?
input byte ?
.code
mainCRTStartup PROC
sub rsp, 32 ;reserve shadow space
push rbp ;save base pointer
mov rbp, rsp ;make base ptr = stack ptr
mGetHandles ;calls this macro to set stdin and stout
mov r12b, namProm ;move namprom into r12 to pass to write console
mWriteConsole ;calls mWriteConsole macro to display prom
mov r12b, myName ;moves name into r12 regester to accept input
mReadConsol ;calls read console to accept input
mov myName, r12b ;moves input back into myname
mov r12b, addProm ;move add prom into r12 to print prompt in write console
mWriteConsole ;call write console to display prompt
mov r12b, address ;move address into r12 to accept input from user
mReadConsol ;call read consol to accept input
mov address, r12b ;move input back into address
mov r12b, prompt ;move prompt into regester to display prompt
mWriteConsole ;call write console to display prompt
mov r12b, myName ;move name into regester to display input name
mWriteConsole ;call write console to display name
mov r12b, address ;move address into regester to display the address
mWriteConsole ;call write console
pop rbp ;clears the base pointer
add rsp, 32 ;restors shadow space
call ExitProcess ;returns to the c++ program
mainCRTStartup ENDP
END