Hello, I am trying to write a program that reads in a string of numbers. I am only allowed to use ReadChar (not ReadString, ReadInt, ReadBin, etc). The program reads in this string of numbers (2-16) which is a base number. Then the user enters another string of numbers. I have to call the same procedure for both. The program converts this 2nd string from the indicated base to base 2, 8, 10, and 16. Right now I am having problems just entering the string of numbers and reading them back as numbers and not ASCII characters. Can someone please point me in the right direction to get started on this first part? Below is the code I have so far. Thank you.
INCLUDE Irvine32.inc
.data
promptBase BYTE "What base (2-16 or 0 to quit)?: ",0
promptVal BYTE "Number please: ",0
outputErrorMsg BYTE "Invalid entry. Try again.",13,10,0
outputBase2 BYTE "Base 2: ",13,10,0
outputBase8 BYTE "Base 8: ",13,10,0
outputBase10 BYTE "Base 10: ",13,10,0
outputBase16 BYTE "Base 16: ",13,10,0
base BYTE 2 DUP(?) ; to hold base value
basesize = ($ - base)
.code
main PROC
call Clrscr
L1:
mov edx, OFFSET promptBase ; "What base (2-16 or 0 to quit)?: "
call WriteString ; print prompt to screen
call ReadInteger
cmp esi, 1 ; if esi = 1, then base value is one digit
je Base1 ; so jump to Base1 Instructions
jmp Base2 ; otherwise jump to Base2 Instructions
Base1:
cmp base[esi], 0 ; if user entered 0
je Quit ; then jump to Quit
cmp base[esi], 1 ; if value is 1, base value is invalid
je Error ; jump to error message
Base2:
cmp base[esi], 7 ; if 2nd value of base is 7 or greater, then base is greater than 16 and invalid
jge Error ; display error msg
jmp RunProgram ; otherwise run program
Error:
mov edx, OFFSET outputErrorMsg ; "Invalid entry. Try again."
call WriteString
mov eax, 0
jmp L1
RunProgram:
;call ReadInteger ; pass value entered to ReadInteger Procedure
;call Crlf
;jmp L1
Quit:
call DumpRegs
exit
main ENDP
;--------------------------------------------------------
ReadInteger PROC
; Description: Reads in a string of numbers and stores them in
; string array called base.
;-------------------------------------------------------------
mov edx, OFFSET base
mov ecx, basesize
L1:
call ReadChar
call WriteChar
mov base[esi], al ; save character into base, position 1
inc esi ; increment pointer
cmp al, 0dh ; if "enter" key pressed
je Return ; then jump to Return
jmp L1 ; otherwise repeat loop
Return:
ret
ReadInteger ENDP
main ENDP