0

-------------------------------------------------- - - - - - 更新 - - - - - - - - - - - - - - - - - - - - ---------------

我正在尝试编写代码以从一个位置反转字符串并将其放置在另一个位置,但在反转部分的开头我一直遇到问题。我想将字符串的最后一个字节加载到另一个寄存器中,但是我得到一个我无法写入的错误。代码是:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
; Question 3 Assignment 3
; Department of Electrical and Computer Engineering
; Hana Ali
; The purpose of this code is to reverse a string and put it in R1
;**************************************************************************
          AREA RESET, CODE, READWRITE
          ENTRY
          ADR  R0, string1              ; R0 is a pointer to string1
          ADR  R1, stringRev            ; R1 is a pointer to stringRev
          MOV  R2, #0                   ; COUNTER
getLength LDRB R3, [R0]                 ; For every byte in R0
          CMP  R3, #0                   
          BEQ  prep                     ; If terminated, go to prep
          ADD  R2, #1                   ; Increment counter
          ADD  R0, #1                   ; Go to next byte in string
          B    getLength                ; Go back to loop
          
prep      ADR  R0, string1              ; R0 pointer to beginning of string
          MOV  R4, #0                   ; Counter for string reversal
          B    reverse                  ; Go to reversing

reverse   SUB  R2, R2, R4               ; R2 - R4 IN R2
          SUB  R2, #1                   ; R2 - R4 - 1 IN R2
          LDRB R5, [R0, R2]!            ; Loads byte R2 - R4 - 1, or length - iteration - 1,
                                        ; into R5. ESSENTIALLY end of string
                                        
          CMP  R4, R2                   ; Compare current iteration with string length
          BEQ  STOP                     ; If reached length, stop
          STRB R5, [R1, R4]             ; Store R5 into location R1 + R4, or start + current
                                        ; iteration
          ADD  R4, #1                   ; Increment iteration
          B    reverse
STOP      B    STOP

string1   DCB  "Goodness Gracious Pan, 0xD",0   
                                        ; Char array pointed to by string1
stringRev DCB   0                       ; Char array pointed to by stringRev
temp      DCB   0
          END

问题上线了

STRB R5, [R1, R4]

原来R0的起始地址是0x00000054,最后一个字节是0x0000006D。当我们开始循环时,我希望 R0 为 0x0000006D([R0, R2]!,其中 R0 为 0x00000054,R2 是要复制的整个字符串的长度减去当前迭代减去 1,因为我删除了最后一个 0,并且R5 为 0x00000044(正确)。但是,当我开始存储时,我收到“无法写入”错误。我不知道为什么。感谢任何帮助!

4

0 回答 0