From ae8cf583245779f156fad2713b6380f64ae629e8 Mon Sep 17 00:00:00 2001
From: an7s <an7s@git.zephyr-software.com>
Date: Wed, 14 Sep 2011 19:22:54 +0000
Subject: [PATCH] widening/truncation examples

---
 .gitattributes   |  1 +
 examples/width.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)
 create mode 100644 examples/width.c

diff --git a/.gitattributes b/.gitattributes
index cc997d9b0..a1848394e 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -152,6 +152,7 @@ examples/mul/run_tests.sh -text
 examples/overflow1.c -text
 examples/test1.c -text
 examples/test2.c -text
+examples/width.c -text
 libIRDB/Makefile -text
 libIRDB/include/cfg/BasicBlock.hpp -text
 libIRDB/include/cfg/CFG.hpp -text
diff --git a/examples/width.c b/examples/width.c
new file mode 100644
index 000000000..d830a1220
--- /dev/null
+++ b/examples/width.c
@@ -0,0 +1,72 @@
+int main(int argc, char **argv)
+{
+  volatile char c = 0;
+  volatile short s = 0;
+  volatile char uc = 0;
+  volatile int i = 0;
+  volatile unsigned short us = 0;
+  volatile int ui = 0;
+
+  // widening
+
+  i = c; /* movzx   eax, [ebp+var_1]
+            movsx   eax, al
+            mov     [ebp+var_C], eax
+         */
+
+  i = uc; /* movzx   eax, [ebp+var_5]
+             movsx   eax, al
+             mov     [ebp+var_C], eax
+          */
+
+  ui = c; /*
+                movzx   eax, [ebp+var_1]
+                movsx   eax, al
+                mov     [ebp+var_14], eax
+          */
+
+  ui = uc; /*   movzx   eax, [ebp+var_5]
+                movsx   eax, al
+                mov     [ebp+var_14], eax
+           */
+
+  s = c;   /*   movzx   eax, [ebp+var_1]
+                cbw                         ; convert byte to word (sign-extend)
+                mov     [ebp+var_4], ax
+           */
+
+  s = uc;  /*   movzx   eax, [ebp+var_5]
+                cbw
+                mov     [ebp+var_4], ax
+           */
+
+  us = c;  /*   movzx   eax, [ebp+var_1]
+                cbw
+                mov     [ebp+var_E], ax
+           */
+
+  us = uc; /*   movzx   eax, [ebp+var_5]
+                cbw
+                mov     [ebp+var_E], ax
+           */
+
+  //
+  // truncating
+  //
+  c = i;   /*   mov     eax, [ebp+var_C]
+                mov     [ebp+var_1], al
+           */
+
+  uc = i;  /*   mov     eax, [ebp+var_C]
+                mov     [ebp+var_5], al
+           */
+
+  s = i;   /*   mov     eax, [ebp+var_C]
+                mov     [ebp+var_4], ax
+           */
+
+  s = ui;  /*   mov     eax, [ebp+var_14]
+                mov     [ebp+var_4], ax
+           */
+
+}
-- 
GitLab