13.2.1.2 - 4


:

Ideal

p586

model flat

include "win.inc"

extrn GetStdHandle:proc

extrn ReadConsoleA: proc

extrn WriteConsoleA:proc

dataseg

buffer db 80 dup (?)

codeseg

proc gets

public gets

arg mystr:dword

local s:dword=r

push ebp

mov ebp, esp

sub esp, r

push ebx ecx

push STD_INPUT_HANDLE

call GetStdHandle;

mov ebx, [ebp+8]

push 0

lea ecx, [ebp-4]

push ecx

push 80 ebx eax

call ReadConsoleA

sub [s], 2

add ebx, [s]

mov [byte ptr ebx], 0

mov eax, [ebp+8]

pop ecx ebx

mov esp, ebp

pop ebp

ret 4

endp

proc puts

public puts

arg mystr1:dword

local s1:dword=r1

push ebp

mov ebp, esp

sub esp, r1

push ebx ecx edx esi

push STD_OUTPUT_HANDLE

call GetStdHandle

mov ebx, [ebp+8]; &

; len

mov edx, 0

mov esi, offset buffer

m2:

mov cl, [ebx+edx]

mov [esi+edx], cl

test cl, cl

jz short m1

inc edx

jmp m2

m1:

push 0

lea ecx, [ebp-4]

push ecx

push edx

push offset buffer

push eax

call WriteConsoleA

mov eax, [ebp+8]

pop esi edx ecx ebx

mov esp, ebp

pop ebp

ret 4

endp

end

:

Ideal

p386

model flat

extrn ExitProcess:proc

extrn GetStdHandle:proc

extrn ReadConsoleA:proc

extrn WriteConsoleA:proc

extrn gets:proc

extrn puts:proc

dataseg

include "win.inc"

din dd 0

dout dd 0

buf db 80 dup (?)

siz dd ?

mystr db 'Input string, please', 13, 10, 0

codeseg

begin:

push offset mystr

call puts

push offset buf

call gets

push offset buf

call puts

call ExitProcess

end begin