Reputation:
I am trying to make a program in which the user will need to type a command in a certain format to preform a calculation, for example, "get a number in Hexa,get another number in binary,subtract them,represent in decimal".
in order to do this I want to take each sentence until the char ','for example: "get a number in Hexa"
and then I will know to which function to jump, I thought about going over the input in a loop and just add it to a variable in which I will compare string with but do know how, here is what i wrote so far:
.model Small
.data
Table db "get a number in decimal,"," get a number in binary,"," get a number in hexa,"," get another number in binary,", "get another number in decimal,", "get another number in hexa"," multply them,"," sum them,", "subtract them,","divide them,","or them,","and them,","xor them," ,"not them,","represent in hexa,", "represen in binary,", "represent in decimal,"
Num dw ?
Num2 dw ?
Result dw ?
Num_count db 1
ourbuffer db ?
temp db ?
FirstS db "Please enter a the command in the following pattern: get a number in hexa,get another number in binary,substract them,represet in decimal",13,10,"$"
.stack 100H
.code
start:
mov AX,@data
mov DS,AX
mov di,0
mov si,0
instructions:
mov dx,offset FirstS ->print instruction to the user
mov ah,09h
int 21h
setBuffer:
mov bx,offset ourBuffer-set buffer
mov dx,bx
mov byte [bx],128
ScanInitialString:->get the string from the user
mov ah,0Ah
int 21h
reset:
mov si,0
mov DI,0
Extract:->here i want to extract each sentance into temp and then compare with Table
MOV Al,0
mov Al,ourbuffer[si]
mov temp[DI],Al
add SI,2
ADD DI,2
jmp Extract
Exit:
mov ax, 4c00H
int 21H
end Start
please assist me?
Upvotes: 1
Views: 204
Reputation: 39166
ourbuffer db ? temp db ? FirstS db "Please ...
get the string from the user (into ourbuffer)
i want to extract each sentance into temp
The definitions of ourbuffer and temp merily reserve a single byte of memory each! To get a decent buffer use something like db 128 dup (0)
.
To learn more about the DOS.BufferedInput function 0Ah read How buffered input works.
Next Extract routine will retrieve all the characters until a "," is found or until the DOS terminating carriage return is found. The CX
register will tell you how many characters were deposited in the temp buffer. This count does not include the terminating comma although that comma is present in the temp buffer.
; IN (si) OUT (cx,si)
Extract:
push ax
mov cx, di ; Preserves DI
mov di, -1
.More:
inc di
mov al, ourbuffer[si]
mov temp[di], al
inc si
cmp al, ","
je .OK
cmp al, 13
jne .More
dec si
mov byte ptr [di], "," ; Replace 13 by ,
.OK:
xchg cx, di
pop ax
ret
To extract the first command use:
mov si, 2 ; The inputted characters start at offset 2 with this DOS function!
call Extract ; -> CX SI
Now you can compare the contents of temp with the records in your long Table. However, you must preserve the SI
index so as to be able to extract any remaining commands from the input in ourbuffer!
To extract following commands keep using:
push si
... Here goes comparing commands, etc
pop si
call Extract ; -> CX SI
If upon returning from Extract CX=0
, then you know that there's nothing more to extract from ourbuffer. Beware, this could have happened at the first extraction already...
Upvotes: 1