Please write comment and write in little endian. Please add detailed contacts. A
ID: 1847098 • Letter: P
Question
Please write comment and write in little endian. Please add detailed contacts. Answer 1a and 1b fully for credit. Thanks in advanced
Explanation / Answer
here the subrotine you are looking for....
routine
STMFD sp!,{r0-r12, lr} ; stack all registers
; and the return address
LDR R0,=stringaddress ;load the string address in R0 for part 2
LDR R1,=count ; load the address to number of bytes to be tested
LDR R1,[R1] ; load the number of bytes value in R1
EOR R6,R6,R6 ; clear R6
again
EOR R5,R5,R5 ; clear R5
LDRB R3,[R0] ; Load character from string
Loop
AND R4,#1,R3 ; clear all the bits except last bit
LSR R3,#1 ; shift by 1
CMP R4,#0 ; check if last bit is one
BNE one
back
ADD R5,R5,#1 ; increment R5
CMP R5,#8 ; check if all the bits the loaded byte are checked
BNE Loop ; continue until all the bits in the loaded byte are checked
ADD R0,R0,#1 ; increment the string pointer
SUB R1,R1,#1 ; decrement the number bytes
CMP R1,#0 ; check if all the bytes are done
BNE again ;
BAL end ;
one
ADD R6,R6,#1 ; last bit is one, increment R6
BAL back
end
AND R6,R6,#1 ; clear all the bits in except the last bit
CMP R6,#0 ; if last bit in R6 is zero then the number of ones in the string will be even
;remember even number always ends with 0 in binary form
LDMFD sp!,{r0-r12, pc} ; load all the registers
; and return automatically
AREA asciiCode,DATA
stringaddress DCW 0xyyyy ; 0xyyyy is the address where the string is stored
count DCW 4 ; assuming the number of bytes to count as 4
END
please reply for any futher clarifications...:)