Lab Threee
Lab Threee
Lab Threee
exit
main endp
Str_length PROC USES edi,
pString:PTR BYTE
mov edi,pString
mov eax,0
L1:
cmp BYTE PTR [edi],0
je L2
inc edi
inc eax
jmp L1
L2: ret
Str_length ENDP
Initialize PROC
pushad
INVOKE GetStdHandle, STD_INPUT_HANDLE
mov [consoleInHandle],eax
INVOKE GetStdHandle, STD_OUTPUT_HANDLE
mov [consoleOutHandle],eax
mov InitFlag,1
popad
ret
Initialize ENDP
CheckInit MACRO
LOCAL exit
cmp InitFlag,0
jne exit
call Initialize
exit:
ENDM
cout PROC
pushad
CheckInit
INVOKE Str_length,edx
cld
INVOKE WriteConsole,
consoleOutHandle,
edx,
eax,
OFFSET bytesWritten,
0
popad
ret
cout ENDP
;--------------------------------------------------------
cin PROC
LOCAL bufSize:DWORD, saveFlags:DWORD, junk:DWORD
.data
_$$temp DWORD ?
.code
pushad
CheckInit
mov edi,edx
mov bufSize,ecx
push edx
INVOKE ReadConsole,
consoleInHandle,
edx,
ecx,
OFFSET bytesRead,
0
pop edx
cmp bytesRead,0
jz L5
dec bytesRead
cld
mov ecx,bufSize
mov al,0Ah
repne scasb
jne L1
dec bytesRead ; second adjustment to bytesRead
sub edi,2 ; 0Ah found: back up two positions
cmp edi,edx ; don't back up to before the user's buffe
r
jae L2
mov edi,edx ; 0Ah must be the only byte in the buffer
jmp L2 ; and jump to L2