views:

92

answers:

1

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
A: 

This is probably a bit late and not a very specific answer, but since no one else has given an answer, I thought I would pop in a few comments.

1 - Sorry, you need to understand the author's library, if you are relying on it for getting your console input. You seem to be saying that eax contains something significant when the routine returns, but you're not sure what? The docs should tell you.

2 - Looks to me as if you are passing a file handle, a buffer, a buffer size and a place to return the number of bytes read into the buffer. I am picking that the buffer will contain a series of bytes, probably terminated by a carriage return, which represent what was typed in.

3 - You just have to go through the buffer one byte at a time, keeping a running total of what the integer is. Need to skip leading spaces, track a '-' or '+' sign, check that all other characters are digits. You seem to be alluding to this in your question, but I have no idea what adding 8 to an offset has to do with any of this?

Hope some of this is timely and gives you a few clues.

Tony van der Peet