在汇编器中访问数组
我在用汇编程序编程时遇到问题。我正在用汇编程序制作“4 in a row”游戏,并且已经成功编写了绘制 7x6 比赛场地的代码。 我使用一个数组来跟踪比赛场地,并使用具有不同颜色代码的数组。
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
为了绘制我的比赛场地,我使用以下代码。
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
我现在遇到的问题是使用变量 CurrentBlock 作为索引,就像 PlayingField[CurrentBlock] 一样。我需要存储这个值,以便我可以在代码的绘图部分使用它作为 CollorList 的索引。就像这个 CollorList[index]. 这样我就需要将值放入 al 寄存器中,这样我就可以得到当前块的值 0 的白色像素,值 1 的黄色像素,值 2 的红色像素。
另外,我现在还想知道如何更改某个索引的值在我的 PlayingField 数组中。因为“ mov PlayingField[currentblock], 2 似乎不起作用。
汇编器对我来说是新的,在网上搜索但还没有找到我的答案。我非常感谢任何帮助。
亲切的问候, 蒂姆
编辑: 我使用 DOS + MASM/LINK。如果这样有效的话会尝试一下。我尝试过类似的方法,但似乎不起作用。
mov si,2
mov bx, [PlayingField+si]
mov al, CollorList[dx]
这给了我一个错误,因为 [PlayingField+si] 是 8 位,bx 16 位。如果我将寄存器更改为“bl”,它会在代码的最后一行抱怨,因为“bl”是一个 8 位寄存器
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 NASM,可以将 mov PlayingField[currentblock], 2 更改为:
If you are using NASM, you can change
mov PlayingField[currentblock], 2
into: