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

5-17 Verify that the following procedure is equivalent to the string_length proc

ID: 3683612 • Letter: 5

Question

5-17 Verify that the following procedure is equivalent to the string_length procedure in section 5.10 which procedure is better and why?

                string_length1:

                                                push                      EBX

                                                sub                         AX,AX

                repeat:                                

                                                cmp                       [EBX], word 0

                                                je                            done

                                                inc                          AX

                                                inc                          EBX

                                                jmp                        repeat

                done:   

                                                pop                        EBX

                                                ret

;tring_length procedure in section 5.10

;        Objective: To write a procedure to compute string length of a NULL-terminated string.

;            Input: String pointer in EBX register.

;           Output: Returns string length in AX.

%include "io.mac"

               

.CODE

global string_length

string_length:

      ; all registers except AX are preserved

      push    ESI            ; save ESI

      mov     ESI,EBX        ; ESI = string pointer

repeat:

      cmp     byte [ESI],0   ; is it NULL?

      je      done           ; if so, done

      inc     ESI            ; else, move to next character

      jmp     repeat         ;       and repeat

done:

      sub     ESI,EBX        ; compute string length

      mov     AX,SI          ; return string length in AX

      pop     ESI            ; restore ESI

      ret

Explanation / Answer

Both procedure perform the same task but procedure string_length1 is better as compared to procedure string_length becuase this procedure string_length required more execution time as compared to string_length1.

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