We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello. I've been looking at a piece of code that I'm not entirely sure what it does.
LDR r0, =str MOV r1, #0 loop LDRB r2, [r0], #1 ADD r1, r1, #1 CMP r2, #0 BNE loop SUB r1, r1, #1 Data Segment Little Endian Format str DCB "mCQ5Gtq",0
From my understanding, DCB loads the string into a word of 32 bits, and each character has its own byte. Little Endian Format means the least significant byte is stored in the lower memory address. LDR makes r0 = the string. LDRB loads the least significant byte held in r0, into r2 offset by 1 bit.
1) Does the least significant byte start with m or q? i.e. would it be <- 0000 0017 (ascii for q) or <- 0000 006D (ascii for m).
2) Does the LDRB operator load the least significant byte from r0 offset by 1 bit, into r2. If so, what would r2 be (just the first loop).
Thank you very much
Equivalent to
char str[] = "mCQ5Gtq"; uint8_t *r0 = str; // pointer is 32-bit wide uint32_t r1 = 0; do { r2 = *r0++; // LDRB r2, [r0], #1 r1++; }while(r2); // while not NUL r1--;
R0 is a 32-bit pointer, for a byte, it reads the byte into R2, and increments R0 by 1
You could always run it in the Simulator - and watch what it does ... ?