I have created a game in TASM MS-DOS that gives the user math exercises and he has to solve them. The exercises are in addition, subtraction, multiplication and division. Each type has a separate function that renders the exercises on the screen.
For some reason, each function always generates the same exercises (different in each function), even though I use the same function for generating the random number.
For example, in the addition exercises, you'll sometimes see "4 + 6" but you'll never see "4 * 6" in the multiplication exercises. Another example is that you'll sometimes see "9 / 1" but not "9 - 1".
Here is the code:
basicRandomNumber1 db ?
basicRandomNumber2 db ?
proc generateBasicRandomNumber
mov ax, 40h
mov es, ax
mov ax, [es:6Ch]
and al, 00000111b
mov [randomNumber], al
mov ax, 40h
mov es, ax
mov ax, [es:6Ch]
and al, 00000001b
add [randomNumber], al
mov ax, 40h
mov es, ax
mov ax, [es:6Ch]
and al, 00000001b
add [randomNumber], al
ret
endp generateBasicRandomNumber
proc Addition
addition:
call AddBreakLines
call AddSpaces
call generateBasicRandomNumber
mov dl, [randomNumber]
mov [basicRandomNumber1], dl
add dl, '0'
mov ah, 2h
int 21h
mov dx, offset plusSign
call printStr
push 1
call sleep
call generateBasicRandomNumber
mov dl, [randomNumber]
mov [basicRandomNumber2], dl
add dl, '0'
mov ah, 2h
int 21h
push 1
call sleep
...the rest of the code
endp Addition
proc Multiplication
Multiplication:
call AddBreakLines
call AddSpaces
call generateBasicRandomNumber
mov dl, [randomNumber]
mov [basicRandomNumber1], dl
add dl, '0'
mov ah, 2h
int 21h
mov dx, offset mulSign
call printStr
push 1
call sleep
call generateBasicRandomNumber
mov dl, [randomNumber]
mov [basicRandomNumber2], dl
add dl, '0'
mov ah, 2h
int 21h
...the rest of the code
endp Multiplication
Sometimes, it logs a message that says there has been an illegal write to some address or an illegal read from there.
The rest of the code means the part where I get the user's input, check if it's equal to the correct result and tell him if it is
the procedure "sleep" is a procedure for making the program sleep for a certain amount of time from the library https://www.github.com/oded8bit/Assembly-Lib
How can I make it so the procedure generateBasicRandomNumber generates different numbers too?
Aucun commentaire:
Enregistrer un commentaire