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

The problem wants you to scan the string \"This is a simple exercise.\" characte

ID: 2988360 • Letter: T

Question

The problem wants you to scan the string "This is a simple exercise." character by character and search for the character 'x'. You do this by making a loop that increments the location you are on by 1 and comparing the character you are on to 'x' to see if it matches, if it does store the location in the register R1. Then it wants you to do the same thing again but for a "null-terminated string" which is a string that is contiguous which has the last binary bit of all zeros. This can be done by doing the same type of loop but don't end it until you read all zeroes meaning it ends. So all you have to do is make a loop that goes on forever reading characters and add an IF statement that jumps out of the loop when it reads all zeroes.

WILL RATE IMMEDIATLY!!!!

Explanation / Answer

   AREA Program,CODE,READONLY
   EXPORT main1
main1
   EOR R0,R0,R0 ; clear contents of r0
   LDR R3,=SOURCE ;
  
Loop
   LDRB R0,[R3] ; load input to R3
CMP R0,#0 ; checking for null terminator
   BEQ Done ; end if null is found
   CMP R0,#120 ; compare with the ascii value of x(120 decimal)
   BEQ Found
back  
ADD R3,R3,#1 ; Increment the source address pointer
   B Loop

Done
   BAL Done ; infinite loop, end of program,

Found
   MOV R1,R3 ; store the address of x in R1 and end
   B back ; continue the loop until null is found

   AREA binarydata,DATA
SOURCE DCB "This is a simple exercise.",0
   END