|  | 
| 7 | 7 | 	; int asm_memcpy(void *dest, const void *src, size_t n); | 
| 8 | 8 | 	; copies n bytes from memory area src to memory area dest | 
| 9 | 9 | asm_memcpy: | 
| 10 |  | -	;;prologue | 
| 11 |  | -pushrbp		; Set up stack frame | 
| 12 |  | -movrbp,rsp | 
| 13 |  | -pushrcx | 
| 14 |  | -pushr15 | 
| 15 |  | -	;;prologue end | 
| 16 |  | - | 
| 17 |  | -movr15b,0		; variable c | 
| 18 |  | -movrcx,rdx		; counter i | 
| 19 |  | - | 
| 20 |  | -;loop_str - while loop | 
| 21 |  | -loop_str: | 
| 22 |  | -cmp[rdi], byte 0 	; (!dest) | 
| 23 |  | -je loopend | 
| 24 |  | -movr15b,[rsi] 	; c = *src | 
| 25 |  | -mov[rdi],r15b ; *dest = c | 
| 26 |  | -addrdi,1		; Increment the first string *dest++; | 
| 27 |  | -addrsi,1		; Increment the second string *src++; | 
| 28 |  | -cmprcx,0		; (count > 0) | 
| 29 |  | -jle loopend | 
| 30 |  | -cmp[rsi], byte 0 	; (!src) | 
| 31 |  | -je loopend | 
| 32 |  | -subrcx,1; | 
| 33 |  | -jmp loop_str | 
| 34 |  | -loopend: | 
| 35 |  | -	;;epilogue | 
| 36 |  | -popr15 | 
| 37 |  | -poprcx | 
| 38 |  | -movrsp,rbp		; Restore previous stack frame | 
| 39 |  | -poprbp | 
| 40 |  | -	;;epilogue end | 
| 41 |  | -ret			; Return from procedure | 
|  | 10 | +movrax,rdi		; Copy the pointer to @dest string to be returned | 
|  | 11 | +movecx,edx		; Copy the length @n to the counter | 
|  | 12 | +cld			; Clear the direction flag, DL | 
|  | 13 | +repmovsb		; Copy @n bytes from ESI (source) to EDI (destination) | 
|  | 14 | +ret			; Return | 
0 commit comments