0

Complete the following code segment which does a memory compare between a and b. The memory compare must be done in a function called memcmp, which is called from the main function. The following must be done:

  1. Set up proper stack frame including frame macro for both main and memcmp functions
  2. a and b must be passed by register from main to memcmp function
  3. memory compare occurs from left to right.
  4. The difference between the first non-equal values must be passed back to main through appropriate register.
  5. If the strings are equal, -1 must be returned in RAX.
  6. Appropriate string compare opcode must be used.

       segment .data 
a      db       "Final Exam!"
b      db       "Final Exan!"        
             
       segment .text
       global  main                    ; Tell linker about main
       global memcmp

memcmp:
       frame    2,0,2                  ;set up the frame macro
       sub      rsp, frame_size
       
       

main:
        frame                        ;set up the frame macro
        sub      rsp, frame_size
        
       

This is all that I have so far, I am a bit stuck on the 2nd part of the instructions. How do I pass a and b from main to the memcmp function?

Peter Cordes
  • 245,674
  • 35
  • 423
  • 606
puyopop
  • 13
  • 4
  • *Appropriate string compare opcode must be used.* - I hope they mean `pcmpeqb` / `pmovmskb`, since this is x86-64, not 8086. `rep cmpsb` isn't faster than SIMD, or even an efficient byte-at-a-time loop. – Peter Cordes Nov 18 '20 at 21:35

0 Answers0