메뉴 건너뛰기

app

[ASM] strcpy

suritam92013.12.06 20:01조회 수 2295댓글 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
2015.05.15 조회 1675
lispro06
2015.05.15 조회 1650
lispro06
2015.05.15 조회 2541
lispro06
2014.08.16 조회 1793
lispro06
2014.02.08 조회 4053
lispro06
2013.12.11 조회 1712
lispro06
2013.12.10 조회 3015
suritam9
2013.12.06 조회 2295
suritam9
2013.12.02 조회 3483
suritam9
2013.11.30 조회 2187
suritam9
2013.11.26 조회 1684
suritam9
2013.08.23 조회 7348
suritam9
2013.08.23 조회 1891
suritam9
2013.06.28 조회 2368
첨부 (3)
vcredist_x86.exe
4.84MB / Download 58
strcpy.exe
7.0KB / Download 61
str.JPG
33.9KB / Download 73
위로