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:
ReadInt PROC
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)
Example:
.data
intNum DWORD ?
promptBad BYTE "Invalid input, please enter again",0
.code
read: call ReadInt
jno goodInput
mov edx,OFFSET promptBad
call WriteString
jmp read ;go input again
goodInput:
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.
My code:
TITLE StringMaker (StringMaker.asm)
; This program randomly generates a user defined number of strings with 10 capital letters.
INCLUDE Irvine32.inc
.data
MSG1 BYTE "Please enter a number beteen 5-15 (inc): ", 0
MSG2 BYTE "Sorry, your input was invalid.", 0
.code
main PROC
jmp L2 ;Skip error MSG (for better order)
L1: mov edx, OFFSET MSG2 ;Error MSG
call WriteString
call crlf
L2: mov edx, OFFSET MSG1 ;Statement MSG
call WriteString
call ReadInt ;Gets Keyboard Input
jo L1 ;If input=invalid ReadInt sets Overflow jump to error
cmp eax, 0b ;If eax=0, exit
je L5
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
call RandomRange
add al, 41h ;Converts AL to ASCII Char 'A'-'Z'
call WriteChar
loop L4 ;Random Char Loop
call Crlf
pop ecx ;pop # of Strings for random loop
loop L3 ;Random String Loop
call Crlf
jmp L2
L5: exit
main ENDP
END main