使用RAW模式在ARM中写入

时间:2014-05-03 22:24:20

标签: assembly arm computer-architecture low-level

所以我目前必须在ARM Assembly中编写Connect 4程序。但是,我有一点问题。我的游戏不允许我在底行上方添加任何筹码。它们只是不存储在数组中。

我已经像这样创建了2D数组:

  .balign 4
board:
  .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

我让用户输入他们的行。但是,它不会添加在最底层之上。

注意:这是一个整数数组。我用-1代表X芯片,1代表O芯片,0代表空(' - ')。

当输入为第1列时,以下方法放置芯片:

itsAOne:
push {lr}
mov r7, #100 @ignore this
mov r5, #0 @this is a check later, to know if we successfuly inserted something

ldr r4, addr_of_board @address of the board
mov r10, #140 @place 35 in the array X 4 bytes
bl oneLoop @loop below

b returns @return method

oneLoop:
push {lr}

CMP r5, #0 @if r5 is not 0, it means we inserted a chip, so we stop
BNE returns

ldr r5, [r4, r10] @we get the value of the bottom of the column
CMP r5, #0 @if it's empty
BLEQ oneInner @we do this method to place a chip

sub r10, r10, #28 @else we subtract 28 to go up a row
bl oneLoop @loop

b returns

oneInner:
push {lr}

mov r1, r9 @these lines are a test to figure out what is in r9
mov r0, #1
mov r2, #4
bl write
bl printNewLine


CMP r9, #1 @if its player 1, place an O
BLEQ playerO

CMP r9, #2 @if it's player 2, place an X
BLEQ playerX

str r5, [r4, r10] @store the new value in the board

b returns

如果我缩小我的问题,我似乎无法打印r9。当我做代码时

mov r1, r9
mov r0, #1
mov r2, #4
bl write
bl printNewLine

除了newLine之外什么都不打印(因为这是原始的\ r \ n,因为它是原始的)。

我一直在扯掉头发,找不到错误。谁能发现我做错了什么?

感谢。

0 个答案:

没有答案