.s파일 빌드 방법은 .c와 같다.

gcc -o prog prog.c

32바이트 빌드는 뒤에 -m32를 붙이면 된다.

%eax에 길이가 들어가겠으나 strlen만으로는 확인할 방법이 없어 GDB로 직접 디버깅하여 실제 문자열 길이가 리턴되는것을 확인하였다.

.globl main
main:
	push %ebp
	mov %esp, %ebp
	push $helloworld
	call strlen
	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 - strcpy  (0) 2015.10.10
블로그 이미지

__미니__

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

,