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

to read a string without readstring simply use readchar inside of a loop.
0. create a pointer to the end of the stack, (first available location in mem) this will be the begining of the string.
1. read the char
2. check if the char is /n
3. if it is /n goto setp 6
4. if it is any other character place it on the stack in main mem
5. goto step 1
6. terminate the stored string with your chosen char standard in c is null, /0

now that we have a string of numbers we can read them starting at the pointer you set earlier.
read the first char to a registry then convert it to its literal value by subtracting 48.
you now have a number stored in your chosen register.

Thank you for the tip...I will try to work on this project more tomorrow night and post the progress.

you could convert the characters to numbers as you read them then store it on the stack as described above. unless you can operate on the numbers right away then don't store it on the stack saves a lot of execution time if you dont have to dump you data to the stack.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.