Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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


Write a subroutine that takes the address of a string in register rO and the number of bytes to count in register rl. It should check for an even number of set bits for each counted character of the string (its hex value). If all the bytes counted have an even parity then the Z flag should be set. If one or more bytes have an odd parity then the Z flag should be cleared. Likewise you can clear the Z flag by performing an operation that is never zero and sets flags. Also note that the string could potentially be longer than the number of bytes in it that we count, but we will never count more bytes than we have in the string. The string will not necessarily be null terminated. Since this is a subroutine you must ensure it is re-entrant, as well as save off the contents of any registers used to the stack and then load them back in at the end of the subroutine. lb) Write a subroutine that performs the same operation as part la, but takes its arguments from memory instead of in register rO and rl. This means that you will have to create a block of memory for parameter usage, and store the address of the string as well as the number of bytes to count in that section. The subroutine will then load these parameters into the registers you use to perform the operation. Again, it must satisfy the requirements of a subroutine.

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...:)