Assembly 使用原始模式在ARM中写入

Assembly 使用原始模式在ARM中写入,assembly,arm,computer-architecture,low-level,Assembly,Arm,Computer Architecture,Low Level,所以我现在必须在ARM汇编中编写一个Connect 4程序。然而,我有点问题。我的游戏不允许我在最底层添加任何筹码。它们只是不存储到数组中 我创建了二维阵列,如下所示: .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 我让用户输入他们的行。但

所以我现在必须在ARM汇编中编写一个Connect 4程序。然而,我有点问题。我的游戏不允许我在最底层添加任何筹码。它们只是不存储到数组中

我创建了二维阵列,如下所示:

  .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
除了换行符外,不打印任何内容(由于换行符是原始的,\r\n因此换行符是原始的)

我一直在为这件事焦头烂额,找不到错误。谁能看出我做错了什么


谢谢。

展示“编写”函数的源代码或api修订大多数人对他们的代码,特别是汇编代码进行注释。我继续为您注释了它。此外,这里的编写文档在代码集
r9
中没有任何内容,但我猜它不包含指向字符串的指针(因为您也在与
#1
#2
进行比较)。在这里使用调试器比上传不完整的代码转储更有效率,只是说