Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #######################################
- # YOUR NAME HERE
- # CSE 378 - Fall 2010
- # Homework 2
- # Due: Monday Oct. 11th, 5pm
- #######################################
- ### Data section
- .section .rodata
- .haystack:
- #.string "Hello World!"
- .string "suhihper duper"
- .needle:
- #.string "ello "
- .string "hih"
- .align 8
- .LC2:
- .string "Found \"%s\" in string \"%s\" at index %lu \n"
- .LC3:
- .string "\"%s\" not found in string \"%s\" \n"
- ### Text section
- .text
- ### Function declarations
- .globl strstr
- .type strstr, @function
- .globl main
- .type main, @function
- #######################################
- # INT MAIN(INT ARGC, CHAR* ARGV[])
- #######################################
- main:
- .cfi_startproc
- pushq %rbp
- .cfi_def_cfa_offset 16
- movq %rsp, %rbp
- .cfi_offset 6, -16
- .cfi_def_cfa_register 6
- pushq %rbx
- subq $56, %rsp
- movl %edi, -52(%rbp)
- movq %rsi, -64(%rbp)
- movq $.haystack, -24(%rbp)
- movq $.needle, -32(%rbp)
- movq -32(%rbp), %rdx
- movq -24(%rbp), %rax
- movq %rdx, %rsi
- movq %rax, %rdi
- .cfi_offset 3, -24
- call strstr
- movq %rax, -40(%rbp)
- cmpq $0, -40(%rbp)
- je .L4
- movq -40(%rbp), %rdx
- movq -24(%rbp), %rax
- movq %rdx, %rcx
- subq %rax, %rcx
- movl $.LC2, %eax
- movq -24(%rbp), %rdx
- movq -32(%rbp), %rbx
- movq %rbx, %rsi
- movq %rax, %rdi
- movl $0, %eax
- call printf
- jmp .L5
- .L4:
- movl $.LC3, %eax
- movq -24(%rbp), %rdx
- movq -32(%rbp), %rcx
- movq %rcx, %rsi
- movq %rax, %rdi
- movl $0, %eax
- call printf
- .L5:
- movl $0, %eax
- addq $56, %rsp
- popq %rbx
- leave
- ret
- .cfi_endproc
- #######################################
- # CHAR* STRSTR(CHAR* STRING, CHAR* TARGET)
- #######################################
- strstr:
- .cfi_startproc
- pushq %rbp
- .cfi_def_cfa_offset 16
- movq %rsp, %rbp
- .cfi_offset 6, -16
- .cfi_def_cfa_register 6
- movq %rdi, -8(%rbp)
- movq %rsi, -16(%rbp)
- #######################################
- # YOUR CODE GOES BELOW THIS LINE AND
- .set_up:
- xorl %eax, %eax
- add $1, %eax
- .loop_back:
- movq %rdi, %rcx
- movq %rsi, %rdx
- cmpsb (%rdi), (%rsi)
- je .done
- #inc %rdi
- jmp .loop_back
- inc %rax;
- call printf
- .done:
- # ABOVE THIS LINE
- #######################################
- leave
- ret
- .cfi_endproc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement