diff --git a/.gitattributes b/.gitattributes index cc997d9b0800c144b7cc8735a677d736ea729fba..a1848394e8b467e5da6914d742b89a79820953a7 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 0000000000000000000000000000000000000000..d830a12204a3689284c2d1e461c21c975df26112 --- /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 + */ + +}