메뉴 건너뛰기

app

[ASM] strcpy

suritam92013.12.06 20:01조회 수 2095댓글 0

  • 3
    • 글자 크기

위 사이트를 보고, 아래와 같이 만들었다. gcc 에서는 그래야 하고, VC 에선 다른 것 같다. 집에서 해봐야 할 듯.

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
static inline char * my_strcpy(char * dest,const char *src);
int main(void) {
    char *inner[100], *in2[100];
    scanf("%s",&in2);
    my_strcpy(inner, &in2);
    printf("in2에 입력받은 %s를 inner에 저장 함.%d", inner,strlen(&in2));
}

static inline char * my_strcpy(char * dest, const char *src)
{
    int d0, d1, d2;
    __asm__ __volatile__(  "1:nt"
                           "lodsbnt"
                           "stosbnt"
                           "testb %%al,%%alnt"
                           "jne 1b"
                           : "=&S" (d0), "=&D" (d1), "=&a" (d2)
                           : "0" (src),"1" (dest) 
                           : "memory");
    return dest;
}
 
 
vs2010 에서 한 소스이다. 7k짜리 release를 실행하려면, 2010 재배포 패키지 5M가 있어야 한다.
 
// strcpy.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//
#include "stdafx.h"
char* mystrcpy(char* dest, char* scr);
int _tmain(int argc, _TCHAR* argv[])
{
 char inner[100]="";
 printf("test");
 mystrcpy(inner, "hello");
 printf("n%s",inner);
 scanf("%s",&inner);
 return 0;
}
char* mystrcpy(char* dest, char* scr){
 int len=0;
 _asm{
  mov edi, scr
START:
  cmp byte ptr [edi], 0x00
   je END
   inc len
   inc edi
   jmp START
END:
  mov edi, dest
   mov esi, scr
   mov ecx, len
   rep movs byte ptr [edi], byte ptr [esi]
 }
 return dest;
}
 
str.JPG

suritam9 (비회원)
  • 3
    • 글자 크기
[XE] 게시판 팁 (by lispro06) [XE] 아이핀 구현 (by suritam9)

댓글 달기

lispro06
2014.08.16 조회 1615
lispro06
2014.02.08 조회 3853
lispro06
2013.12.11 조회 1527
lispro06
2013.12.10 조회 2783
suritam9
2013.12.06 조회 2095
suritam9
2013.12.02 조회 3222
이전 1 2 3 4 5 6 7 8 9 10... 15다음
첨부 (3)
vcredist_x86.exe
4.84MB / Download 46
strcpy.exe
7.0KB / Download 49
str.JPG
33.9KB / Download 65
위로