Show Parent Post
Hide Parent Post
Author: Therese Landry
Date: Monday, November 19, 2007 5:41:43 PM CST
Subject: RE: HW_6
Are there more than one ways to detect if a letter is entered rather than a number? I didnt realize I had to do this until today..
There's supposed to be. This is the Irvine help file for ReadInt:
Reads a 32-bit signed decimal integer from standard input, stopping when the Enter key is pressed.
All valid digits occurring before a non-numeric character are converted to the integer value.
Leading spaces are ignored, and an optional leading + or - sign is permitted.
ReadInt will display an error message, set the Overflow flag, and reset EAX to zero if the value entered cannot be represented as a 32-bit signed integer.
Call args: None
Return args: If OF=0, EAX = valid binary value, and SF=sign.
If OF=1, EAX = 0 (invalid input)
intNum DWORD ?
promptBad BYTE "Invalid input, please enter again",0
read: call ReadInt
mov edx,OFFSET promptBad
jmp read ;go input again
mov intNum,eax ;store good value
The problem with my code is that i'm trying to use read int, followed by a JO. The only problem is the overflow won't set when you enter a letter. I saw this because I used DumpRegs afterentering a letter into ReadInt.
TITLE StringMaker (StringMaker.asm)
; This program randomly generates a user defined number of strings with 10 capital letters.
MSG1 BYTE "Please enter a number beteen 5-15 (inc): ", 0
MSG2 BYTE "Sorry, your input was invalid.", 0
jmp L2 ;Skip error MSG (for better order)
L1: mov edx, OFFSET MSG2 ;Error MSG
L2: mov edx, OFFSET MSG1 ;Statement MSG
call ReadInt ;Gets Keyboard Input
jo L1 ;If input=invalid ReadInt sets Overflow jump to error
cmp eax, 0b ;If eax=0, exit
cmp eax, 15d ;If eax>15 -
ja L1 ;Jump L1 (error)
cmp eax, 5d ;If eax<5 -
jb L1 ;Jump L1 (error)
mov ecx, eax ;Move # of String to output to counter
L3: push ecx ;Push # of strings for random loop
mov ecx, 10d ;Counter for 1 string of 10 char
L4: mov eax, 26d ;RandomRange of 0-25
add al, 41h ;Converts AL to ASCII Char 'A'-'Z'
loop L4 ;Random Char Loop
pop ecx ;pop # of Strings for random loop
loop L3 ;Random String Loop