Guest User

Untitled

a guest
Feb 20th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Framework for strlen question
  2.  
  3.     B main
  4. ; you'll need a few more string declarations here to get the answer `looking right'.
  5. text1   DEFB    "Hello World. Goodbye Universe\0"
  6. text2   DEFB    "1234567890 are the ten decimal digits\0"
  7. nulltxt DEFB    "\0"
  8.     ALIGN
  9.  
  10. main    ADR R0, text1   ; get address of starting byte of string
  11.     MOV R2, #0  ; Initialise the counter in Register 2
  12.     ADR R3, nulltxt ; load R3 with null for comparison later on
  13.    
  14. again   LDRB R1, [R0]   ; this loads into r1 the byte whose address is currently in R0
  15.     LDRB R4, [R3]
  16.     CMP R1, R4  ; performs comparison to check if R1 is null
  17.     BEQ end     ; if equal, must have come to end of string - branch to end
  18.     ADD R2, R2, #1  ;add 1 to counter if not the null
  19.     ADD R0, R0, #1      ;add 1 to the byte address
  20.     B again
  21.    
  22. end MOV R0, R2  ;move counter value
  23.     SWI 4       ;print out counter value
  24.     SWI 2       ;end program
Add Comment
Please, Sign In to add comment