https://github.com/akkartik/mu/blob/master/022div.cc
 1 //: helper for division operations: sign-extend EAX into EDX
 2 
 3 :(before "End Initialize Op Names")
 4 put_new(Name, "99", "sign-extend EAX into EDX (cdq)");
 5 
 6 :(code)
 7 void test_cdq() {
 8   Reg[EAX].i = 10;
 9   run(
10       "== code 0x1\n"
11       "99\n"
12   );
13   CHECK_TRACE_CONTENTS(
14       "run: sign-extend EAX into EDX\n"
15       "run: EDX is now 0x00000000\n"
16   );
17 }
18 
19 :(before "End Single-Byte Opcodes")
20 case 0x99: {  // sign-extend EAX into EDX
21   trace(Callstack_depth+1, "run") << "sign-extend EAX into EDX" << end();
22   Reg[EDX].i = (Reg[EAX].i < 0) ? -1 : 0;
23   trace(Callstack_depth+1, "run") << "EDX is now 0x" << HEXWORD << Reg[EDX].u << end();
24   break;
25 }
26 
27 :(code)
28 void test_cdq_negative() {
29   Reg[EAX].i = -10;
30   run(
31       "== code 0x1\n"
32       "99\n"
33   );
34   CHECK_TRACE_CONTENTS(
35       "run: sign-extend EAX into EDX\n"
36       "run: EDX is now 0xffffffff\n"
37   );
38 }