Read a buffer of unknown size (Console input)

Posted by Sanarothe on Stack Overflow See other posts from Stack Overflow or by Sanarothe
Published on 2009-11-23T21:57:41Z Indexed on 2010/04/15 0:03 UTC
Read the original article Hit count: 404

Filed under:
|
|

Hi. I'm a little behind in my X86 Asm class, and the book is making me want to shoot myself in the face. The examples in the book are insufficient and, honestly, very frustrating because of their massive dependencies upon the author's link library, which I hate. I wanted to learn ASM, not how to call his freaking library, which calls more of his library.

Anyway, I'm stuck on a lab that requires console input and output. So far, I've got this for my input:

    input PROC
INVOKE ReadConsole, inputHandle, ADDR buffer, Buf - 2, ADDR bytesRead, 0
mov eax,OFFSET buffer
    Ret
input EndP

I need to use the input and output procedures multiple times, so I'm trying to make it abstract. I'm just not sure how to use the data that is set to eax here. My initial idea was to take that string array and manually crawl through it by adding 8 to the offset for each possible digit (Input is integer, and there's a little bit of processing) but this doesn't work out because I don't know how big the input actually is. So, how would you swap the string array into an integer that could be used?

Full code: (Haven't done the integer logic or the instruction string output because I'm stuck here.)

include c:/irvine/irvine32.inc
.data
inputHandle HANDLE ?
outputHandle HANDLE ?
buffer BYTE BufSize DUP(?),0,0
bytesRead DWORD ?
str1 BYTE "Enter an integer:",0Dh, 0Ah
str2 BYTE "Enter another integer:",0Dh, 0Ah
str3 BYTE "The higher of the two integers is: "
int1 WORD ?
int2 WORD ?
int3 WORD ?
Buf = 80

.code
main PROC
call handle
push str1
call output
call input
push str2
call output
call input
push str3
call output
call input


main EndP

larger PROC


    Ret
larger EndP

output PROC
INVOKE WriteConsole

    Ret
output EndP

handle PROC USES eax
INVOKE GetStdHandle, STD_INPUT_HANDLE
mov inputHandle,eax

INVOKE GetStdHandle, STD_INPUT_HANDLE
mov outputHandle,eax

    Ret
handle EndP

input PROC
INVOKE ReadConsole, inputHandle, ADDR buffer, Buf - 2, ADDR bytesRead, 0
mov eax,OFFSET buffer
    Ret
input EndP

END main

© Stack Overflow or respective owner

Related posts about assembly

Related posts about homework