33
I’m doing an implementation of a game on Assembly in the Proteus.
I draw two random numbers from 1 to 99 and need to generate on the LCD an image referring to the numbers I generated.
Example: If I generate the number 1 the image that will appear on the display is
If I generate the number 2 the image that will appear on the display is
Implementation was done as follows:
.DATA
SEED DW 0 ;Armazena o número aleatório de 1 ~ 99
NUMBER1 DW 0 ;Guarda o primeiro número gerado
NUMBER2 DW 0 ;Guarda o segundo número gerado
IMG_NUMBER1 DW ? ;variavel aux para armazenar a IMG do primeiro numero gerado
IMG_NUMBER2 DW ? ;variavel aux para armazenar a IMG do segundo numero gerado
IMG_NUMERO_1 db 8, 6
db 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
db 030H,0D0H,010H,010H,010H,010H,010H,010H,060H,080H,000H,000H,000H,000H,000H,000H
db 000H,000H,000H,000H,000H,000H,080H,060H,010H,010H,010H,010H,010H,010H,0D0H,030H
db 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
db 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,00CH,034H
db 0C2H,001H,000H,000H,000H,000H,000H,000H,000H,000H,001H,001H,002H,002H,002H,002H
db 002H,002H,002H,002H,001H,001H,000H,000H,000H,000H,000H,000H,000H,000H,001H,0C2H
db 034H,00CH,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
db 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
db 0F0H,00FH,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
db 000H,000H,000H,000H,004H,0FEH,000H,000H,000H,000H,000H,000H,000H,000H,00FH,0F0H
db 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
db 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
db 003H,01CH,060H,080H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
db 000H,000H,000H,000H,002H,003H,002H,000H,000H,000H,000H,000H,080H,060H,01CH,003H
db 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
db 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
db 000H,000H,000H,000H,001H,001H,002H,002H,002H,004H,004H,004H,008H,008H,010H,020H
db 020H,010H,008H,008H,004H,004H,004H,002H,002H,002H,001H,001H,000H,000H,000H,000H
db 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
IMG_NUMERO_2 db 8,6
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB 030H,0D0H,010H,010H,010H,010H,010H,010H,060H,080H,000H,000H,000H,000H,000H,000H
DB 000H,000H,000H,000H,000H,000H,080H,060H,010H,010H,010H,010H,010H,010H,0D0H,030H
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,00CH,034H
DB 0C2H,001H,000H,000H,000H,000H,000H,000H,000H,000H,001H,001H,002H,002H,002H,002H
DB 002H,002H,002H,002H,001H,001H,000H,000H,000H,000H,000H,000H,000H,000H,001H,0C2H
DB 034H,00CH,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB 0F0H,00FH,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB 000H,000H,004H,082H,042H,022H,01CH,000H,000H,000H,000H,000H,000H,000H,00FH,0F0H
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB 003H,01CH,060H,080H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB 000H,000H,003H,002H,002H,002H,003H,000H,000H,000H,000H,000H,080H,060H,01CH,003H
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB 000H,000H,000H,000H,001H,001H,002H,002H,002H,004H,004H,004H,008H,008H,010H,020H
DB 020H,010H,008H,008H,004H,004H,004H,002H,002H,002H,001H,001H,000H,000H,000H,000H
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
..... IMG_NUMERO_3, IMG_NUMERO_4 ... até 99
In the code I wrote so to generate the random number and save in auxiliary variables for comparison at the end of the game:
CALL RANDOM
MOV NUMBER1, SEED ;Guarda o primeiro numero gerado
CALL RANDOM
MOV NUMBER2, SEED ;Guarda o segundo numero gerado
I have NUMBER1 and NUMBER2 the values of the generated random numbers.
I did as follows to fetch the generated number and store the memory position of the image referring to the number: ( Store in BL before calling COMPARE_NMB
, the value 0 to fetch the image of NUMBER1 and 1 for NUMBER2; In AX contains the value of NUMBER*)
COMPARE_NMB:
PUSHF
PUSH BX
PUSH AX
PUSH CX
CMP AX, 1
JE JE_1 ;PULA PRO METODO SE FOR 1
CMP AX, 2
JE JE_2 ;PULA PRO METODO SE FOR 2
CMP AX, 3
JE JE_3
... assim por diante até 99 ...
For each JUst AndWhich I call it:
JE_1:
LEA SI, IMG_NUMERO_1
JMP CONTINUE
JE_2:
LEA SI, IMG_NUMERO_2
JMP CONTINUE
....
CONTINUE:
CMP BL, 0 ;VERIFICAR AONDE ARMAZENAR
JE ARMAZENAR_IMG1
JNE ARMAZENAR_IMG2
...
ARMAZENAR_IMG1:
MOV IMG_NUMBER1, SI
JMP FINALIZAR
ARMAZENAR_IMG2:
MOV IMG_NUMBER2, SI
JMP FINALIZAR
But I don’t think it’s the best solution.
Would anyone know a more practical method?
Create a new variable and store as a array of memory positions, if I want to image1 I would just do posicoesImagens[NUMBER1]
, or imagem2, posicoesImagens[NUMBER2]
, something like that.
Note: Yes, I currently generated 99 variables to store each image for each number. My editor is even locking by the amount of information in the code.
I wrote 500 lines just to compare what the generated number is. And I had to write 2178 lines referring to the images of each number.
DS stands for Data Segment.
I do not program in Assembly, so I do not know if you did there, but ... There is no way to make one
loop
to store the values in each variable, adding +1 in the variable name?? Searching here, I found this link that talks about loop in assbemly, may be useful. It is possible to compile your code online for testing HERE!– Marcos Henzel
@Marcoshenzel do not know how to do what you are talking, my knowledge is as I put in the code above. I want to remove the 500 lines of comparisons that I made and optionally if someone knows some method so that instead of creating 99 variables of the numbers, I need to create only 1 image and put the number in the center within that image at runtime.
– Don't Panic
I don’t work with Assembly, but in your case wouldn’t it be more appropriate to use some matrix (array)? This page should contain some useful information: https://www.tutorialspoint.com/assembly_programming/assembly_arrays.htm
– Carlos Andrade
@M8n yes, as I put it there. 8.6
– Don't Panic
To extend the suggestions, an array would essentially be a list of pointers, which are "locations" or addresses of a specific image. In your case it could be an array of images (order from smaller to larger), or, I mean, an array of pointers of a specific image. Each pointer should be the same size in bytes. To get the pointer’s location (or address) just do
endereçoDaLista + númeroDaImagem * tamanhoDoPonteiro
, for example. Unfortunately I don’t know much Assembly, so I can’t help either :/– Klaider
The position of the first image is starting from 1, but could start at 0. This will depend on how the array is stored in tbm memory.
– Klaider
(My comment got a little confused, but blz :v)
– Klaider
@Polardigit well, but that’s what I want to do, but I have no knowledge of how to do it. Create a new variable and store as an array of memory positions, if I want to image1 I would just do
posicoesImagens[1]
, or imagem2,posicoesimagem[2]
, something like that.– Don't Panic