Memory Array

28

I'm doing an implementation of a game in in < a href="https://www.labcenter.com/"> Proteus .

I draw two random numbers from 1 to 99 and need to generate an image on the LCD for the numbers I generated.

Example: If I generate number 1 the image that will appear in the display is

IfIgeneratenumber2theimagethatwillappearinthedisplayis

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 like this to generate the random number and save in the 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 random numbers generated.

I made the following way to search the generated number and store the memory position of the image referring to the number: (Stores in BL before calling COMPARE_NMB , value 0 to fetch the image of NUMBER1 and 1 for NUMBER2 ; In AX it 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 J E what 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 do not think it's the best solution.

Would anyone know a more practical method?

Create a new variable and store it as an array of memory locations , if I want to image1 I would only do posicoesImagens[NUMBER1] , or image2 , posicoesImagens[NUMBER2] , something like this.

Note: Yes, I currently generated 99 variables to store each image for each number. My editor is still struggling with the amount of information in the code.

I wrote 500 lines just to compare what the number is generated. And I had to write 2178 lines relating to the images of each number.

DS stands for Data Segment.

    
asked by Don't Panic 24.06.2017 в 22:29
source

1 answer

-1

A possible solution would be to write the code in C and ask the compiler to generate the assembly for you.

gcc -Wall -c programa.c
    
answered by 26.09.2017 в 16:30