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

Write a subroutine called STRLEN that determines the length of a null-terminated

ID: 3809069 • Letter: W

Question

Write a subroutine called STRLEN that determines the length of a null-terminated ASCII string. Pass the 32-bit start address of the string to the subroutine in register R0. Return the length, excluding the null byte, in register R7. All registers (except R7) should return to the calling program unchanged.

NOTE: Write a short program which will load the required data into registers and then branch with link to the subroutine.

Write the program in ARM assembly language. Make sure it compiles and executes with VisUAL ARM Emulator that is available on Windows/Mac/Linux. Post code here. Thanks!

Explanation / Answer

I am of the view, that the following question answers your query to a great extent. I hope it helps. Open to further doubts. The programme working in ARM assembly language on all OS is as follows: .global csinsert csinsert: stmfd sp!,{v1-v6,lr} // preserve caller registers // preserve our arguments across calls mov v1,a1 mov v2,a2 mov v3,a3 // get length of destination string mov a1,v1 // set dest addr as strlen arg bl strlen // call strlen add a1,a1,#1 // increment length mov v4,a1 // save it add v3,v3 // src = src + src (what???) mov v5,v2 // save it add v3,v3 // double the offset (what???) bl malloc // get heap memory mov v4,#0 // set index for loop loop: ldrb v7,[v1],#1 subs v2,v2,#1 add v7,v7,a2 strb v7,[a1],#1 bne loop ldmfd sp!,{v1-v6,pc} @std // restore caller registers .end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote