Вопрос

I'm having a problem while programming in assembler. I'm making the game "4 in a row" in assembler and already managed to write the code to draw the playing field of 7x6. I'm using a array to keep track of the playing field and use a array with the different collor codes.

  PlayingField DB 42 DUP(0)   ;0 for empty, 1 for yellow, 2 for res
  CollorList DB 1111b, 1110b, 0100b (white, yellow, res)
  CurrentBlock DB 0

To draw my playing field I use the following code.

  mov al, CollorList[2]    ;collor register
  mov ch, 000000
  mov dh, 000000
  mov cl, Position[0]
  mov dl, Position[1]
  mov ah, 0ch
  int 10h                   ;set pixel

The problem I now have it to use the variable CurrentBlock as a index like this PlayingField[CurrentBlock]. This value I need to store so I can use it in the drawing section of the code as the index of the CollorList. Like this CollorList[index]. This way value I then need to put into the al register so I get a white pixel for the value 0 of the currentblock, yellow for value 1 and red for value 2.

Also I should like to now how I change the value an certain index in my PlayingField array. Because " mov PlayingField[currentblock], 2 doesn't seem to work.

Assembler is new to me and searched online but didn't find my answer yet. Any help I greatly appreciated.

Kind Regards, Tim

Edit: Im using DOS + MASM/LINK. Will try it if it works this way. I tryed something like this but doesn't seem to work.

mov si,2    
mov bx, [PlayingField+si] 
mov al, CollorList[dx]

This gives me an error because [PlayingField+si] is 8bit and bx 16bit. If I change my register to an 'bl' it complains in the last line of the code because 'bl' is a 8bit register

Это было полезно?

Решение

If you are using NASM, you can change mov PlayingField[currentblock], 2 into:

mov si, [currentblock]
mov byte [playingfield+si], 2
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top