1#include <stdint.h> 2#include <string.h> 3#include <stdio.h> 4 5char buf1[64], buf2[64]; 6 7int 8main (void) 9{ 10 unsigned long rdi, rsi, rcx, rax; 11 uintptr_t b1 = (uintptr_t) buf1, b2 = (uintptr_t) buf2; 12 13 if (b1 > 0xffffffffULL || b2 > 0xffffffffULL) 14 return 0; 15 16 b1 += 0x100000000ULL; 17 b2 += 0xfff00000000ULL; 18 memcpy (buf1, "abcde", 4); 19 asm volatile ("addr32 rep movsb" 20 : "=D" (rdi), "=S" (rsi), "=c" (rcx) 21 : "D" (b2), "S" (b1), "c" (0x100000004ULL) 22 : "memory"); 23 if (memcmp (buf2, "abcd", 5) != 0 24 || rdi != (uintptr_t) buf2 + 4 25 || rsi != (uintptr_t) buf1 + 4 26 || rcx) 27 fprintf (stderr, "addr32 rep movsb wrong\n"); 28 29 rax = 0x751234560000ULL + (' ' << 8) + '0'; 30 asm volatile ("addr32 rep stosw" 31 : "=D" (rdi), "=c" (rcx), "+a" (rax) 32 : "D" (b2), "c" (0x100000003ULL) 33 : "memory"); 34 if (memcmp (buf2, "0 0 0 ", 7) != 0 35 || rdi != (uintptr_t) buf2 + 6 36 || rcx 37 || rax != 0x751234560000ULL + (' ' << 8) + '0') 38 fprintf (stderr, "addr32 rep stosw wrong\n"); 39 40 asm volatile ("addr32 lodsl" 41 : "=S" (rsi), "=a" (rax) 42 : "S" (b2), "a" (2ULL)); 43 if (rsi != (uintptr_t) buf2 + 4 44 || rax != 0x20302030ULL) 45 fprintf (stderr, "addr32 lodsl wrong\n"); 46 47 memcpy (buf1, "abcdefghijklmno", 16); 48 memcpy (buf2, "abcdefghijklmnO", 16); 49 asm volatile ("addr32 repe cmpsb" 50 : "=D" (rdi), "=S" (rsi), "=c" (rcx) 51 : "D" (b2), "S" (b1), "c" (0x100000020ULL)); 52 if (rdi != (uintptr_t) buf2 + 15 53 || rsi != (uintptr_t) buf1 + 15 54 || rcx != 17ULL) 55 fprintf (stderr, "addr32 repe cmpsb wrong\n"); 56 57 memcpy (buf2, "ababababababababcdab", 20); 58 rax = 0x123450000ULL + ('d' << 8) + 'c'; 59 asm volatile ("addr32 repne scasw" 60 : "=D" (rdi), "=c" (rcx), "+a" (rax) 61 : "D" (b2), "c" (0x100000020ULL)); 62 if (rdi != (uintptr_t) buf2 + 18 63 || rcx != 23ULL 64 || rax != 0x123450000ULL + ('d' << 8) + 'c') 65 fprintf (stderr, "addr32 repne scasw wrong\n"); 66 67 rax = 0x543210000ULL + ('b' << 8) + 'a'; 68 asm volatile ("addr32 repe scasw" 69 : "=D" (rdi), "=c" (rcx), "+a" (rax) 70 : "D" (b2), "c" (0x100000020ULL)); 71 if (rdi != (uintptr_t) buf2 + 18 72 || rcx != 23ULL 73 || rax != 0x543210000ULL + ('b' << 8) + 'a') 74 fprintf (stderr, "addr32 repe scasw wrong\n"); 75 76 return 0; 77} 78