SHARE
TWEET

Untitled

a guest Jun 19th, 2017 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #######################################
  2. # YOUR NAME HERE
  3. # CSE 378 - Fall 2010
  4. # Homework 2
  5. # Due: Monday Oct. 11th, 5pm
  6. #######################################
  7.  
  8. ### Data section
  9.     .section    .rodata
  10. .haystack:
  11.     #.string    "Hello World!"
  12.     .string "suhihper duper"
  13. .needle:
  14.     #.string    "ello "
  15.     .string "hih"
  16.     .align 8
  17. .LC2:
  18.     .string "Found \"%s\" in string \"%s\" at index %lu \n"
  19. .LC3:
  20.     .string "\"%s\" not found in string \"%s\" \n"
  21.  
  22. ### Text section
  23.     .text
  24. ### Function declarations
  25. .globl strstr
  26.     .type   strstr, @function
  27. .globl main
  28.     .type   main, @function
  29.  
  30. #######################################
  31. # INT MAIN(INT ARGC, CHAR* ARGV[])
  32. #######################################
  33. main:
  34.     .cfi_startproc
  35.     pushq   %rbp
  36.     .cfi_def_cfa_offset 16
  37.     movq    %rsp, %rbp
  38.     .cfi_offset 6, -16
  39.     .cfi_def_cfa_register 6
  40.     pushq   %rbx
  41.     subq    $56, %rsp
  42.     movl    %edi, -52(%rbp)
  43.     movq    %rsi, -64(%rbp)
  44.     movq    $.haystack, -24(%rbp)
  45.     movq    $.needle, -32(%rbp)
  46.     movq    -32(%rbp), %rdx
  47.     movq    -24(%rbp), %rax
  48.     movq    %rdx, %rsi
  49.     movq    %rax, %rdi
  50.     .cfi_offset 3, -24
  51.     call    strstr
  52.     movq    %rax, -40(%rbp)
  53.     cmpq    $0, -40(%rbp)
  54.     je  .L4
  55.     movq    -40(%rbp), %rdx
  56.     movq    -24(%rbp), %rax
  57.     movq    %rdx, %rcx
  58.     subq    %rax, %rcx
  59.     movl    $.LC2, %eax
  60.     movq    -24(%rbp), %rdx
  61.     movq    -32(%rbp), %rbx
  62.     movq    %rbx, %rsi
  63.     movq    %rax, %rdi
  64.     movl    $0, %eax
  65.     call    printf
  66.     jmp .L5
  67. .L4:
  68.     movl    $.LC3, %eax
  69.     movq    -24(%rbp), %rdx
  70.     movq    -32(%rbp), %rcx
  71.     movq    %rcx, %rsi
  72.     movq    %rax, %rdi
  73.     movl    $0, %eax
  74.     call    printf
  75. .L5:
  76.     movl    $0, %eax
  77.     addq    $56, %rsp
  78.     popq    %rbx
  79.     leave
  80.     ret
  81.     .cfi_endproc
  82.  
  83.  
  84. #######################################
  85. # CHAR* STRSTR(CHAR* STRING, CHAR* TARGET)
  86. #######################################
  87. strstr:
  88.     .cfi_startproc
  89.     pushq   %rbp
  90.     .cfi_def_cfa_offset 16
  91.     movq    %rsp, %rbp
  92.     .cfi_offset 6, -16
  93.     .cfi_def_cfa_register 6
  94.     movq    %rdi, -8(%rbp)
  95.     movq    %rsi, -16(%rbp)
  96.  
  97. #######################################
  98. # YOUR CODE GOES BELOW THIS LINE AND
  99.  
  100. .set_up:
  101.     xorl %eax, %eax
  102.     add $1, %eax
  103.  
  104.  
  105.  
  106. .loop_back:
  107.     movq %rdi, %rcx
  108.     movq %rsi, %rdx
  109.     cmpsb (%rdi), (%rsi)
  110.     je .done
  111.     #inc %rdi
  112.     jmp .loop_back
  113.     inc %rax;
  114. call    printf
  115.  
  116. .done: 
  117.    
  118.    
  119.        
  120.  
  121. #         ABOVE THIS LINE
  122. #######################################
  123.     leave
  124.     ret
  125.     .cfi_endproc
RAW Paste Data
Top