main에 버퍼를 할당하고 만들어둔 string 을 strcpy를 이용해 복사하여 출력하는 소스

.globl main
main:
	push %ebp
	mov %esp, %ebp
	sub $0x20, %esp
	lea -0x20(%ebp), %eax
	push $helloworld
	push %eax
	call strcpy
	lea -0x20(%ebp), %eax
	push %eax
	call strlen
	mov %eax, %edx
	mov $0x04, %eax
	mov $0x01, %ebx
	lea -0x20(%ebp), %ecx
	int $0x80
	leave
	ret

strcpy:
	push %ebp
	mov %esp, %ebp
	xor %eax, %eax
	mov 0x08(%ebp), %edi
	mov 0x0c(%ebp), %esi
	.strcpy_loop:
		movb (%esi), %al
		movb %al, (%edi)
		cmpb $0x00, %al
		je .strcpy_finish
		inc %esi
                inc %edi
		jmp .strcpy_loop
	.strcpy_finish:
		leave
		ret


strlen:
	push %ebp
	mov %esp, %ebp
	xor %ecx, %ecx
	mov 0x08(%ebp), %eax
	.strlen_loop:
		movb (%eax), %bl
		cmpb $0x00, %bl
		je .strlen_finish
		inc %eax
		inc %ecx
		jmp .strlen_loop
	.strlen_finish:
		mov %ecx, %eax
		leave
		ret


helloworld : .string "Hello, World"


'Programming' 카테고리의 다른 글

Assembly Programming - isAlpha, isNumber  (0) 2015.10.11
Assembly Programming - gets  (0) 2015.10.10
Assembly Programming - strchr  (0) 2015.10.10
Assembly Programming - puts  (0) 2015.10.10
Assembly Programming - strlen  (0) 2015.10.10
블로그 이미지

__미니__

E-mail : skyclad0x7b7@gmail.com 나와 계약해서 슈퍼 하-카가 되어 주지 않을래?

,