Issues with Writing

0

------------------------------------------------------------ UPDATED ------------------------------------------------------

I'm trying to make a code to reverse a string from one location and place it in another, but I keep getting an issue in the start of the reverse part. I want to load the last byte of the string into another register, but I get an error that I can't write. The code is:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
; 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

The issue is on the line

STRB R5, [R1, R4]

Originally, R0's starting address is 0x00000054, and last byte is at 0x0000006D. When we start the loop, I expect R0 to be 0x0000006D ([R0, R2]!, where R0 is 0x00000054, R2 is the length of the entire string to copy minus the current iteration minus 1, as I remove the last 0, and R5 as 0x00000044 (correct). But, when I get to storing, I get an "unable to write" error. I'm not sure why. Any help is appreciated!

assembly
arm7
asked on Stack Overflow Oct 23, 2020 by Hana Ali • edited Oct 23, 2020 by Hana Ali

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0