{"id":213,"date":"2012-05-07T21:45:41","date_gmt":"2012-05-07T19:45:41","guid":{"rendered":"http:\/\/kronotai.com\/wordpress\/?p=213"},"modified":"2012-05-07T21:45:41","modified_gmt":"2012-05-07T19:45:41","slug":"modulo-arithmetic-and-twos-complement","status":"publish","type":"post","link":"https:\/\/kronotai.com\/wordpress\/2012\/05\/07\/modulo-arithmetic-and-twos-complement\/","title":{"rendered":"Modulo arithmetic and two&#039;s complement"},"content":{"rendered":"<p>\t\t\t\t<![CDATA[One of the reasons why the upcoming version 1.2 takes so long is that the way numbers are modeled internally are reworked. Concrete numbers are modeled as an expression. Expressions have an identify which is used to form the type graph. There are the usual expressions which model an addition, the negating of a number, a load or a global (well the address of the global). There is a specific expression which represents for a concrete number. Previously this was modeled as the largest Java integer type  (long) which is a signed 64 bit without the information what size this number has. This old model would yield 256 for 255+1 which is incorrect when the number (e.g. the register) is only 8 bits wide. Another problem was that this signed 64 bit integer can not be used for unsigned 64 bit multiplication\/division which ia32 supports. In the upcoming holdec release all values have a width which will take care of the modulo property (e.g. 255+1=0).\nThe two's complement is used to represent negative numbers: -x = (~x)+1. One side effect is that there are two values for which x=-x is true. The one obvious value is zero. But there is another value: -128 for a 8 bit number. Why is this relevant for a decompiler? Well the decompiler transforms the code and usually uses the normal transformation rules. So -x<0 can be transformed to x>0. Right? Wrong. If x=-128 then we get -(-128)<0 => -128<0 => true while for x>0 we get -128>0 => false. So -x<0 should be transformed to x>0 || x==-128. However it is not clear if this second form is easier to understand and so be preferred.\n]]>\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\t\t\t\t<![CDATA[]]>\t\t <a href=\"https:\/\/kronotai.com\/wordpress\/2012\/05\/07\/modulo-arithmetic-and-twos-complement\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,4,5],"tags":[],"class_list":["post-213","post","type-post","status-publish","format-standard","hentry","category-decompiler","category-holdec","category-holdec1-2"],"_links":{"self":[{"href":"https:\/\/kronotai.com\/wordpress\/wp-json\/wp\/v2\/posts\/213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kronotai.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kronotai.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kronotai.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kronotai.com\/wordpress\/wp-json\/wp\/v2\/comments?post=213"}],"version-history":[{"count":0,"href":"https:\/\/kronotai.com\/wordpress\/wp-json\/wp\/v2\/posts\/213\/revisions"}],"wp:attachment":[{"href":"https:\/\/kronotai.com\/wordpress\/wp-json\/wp\/v2\/media?parent=213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kronotai.com\/wordpress\/wp-json\/wp\/v2\/categories?post=213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kronotai.com\/wordpress\/wp-json\/wp\/v2\/tags?post=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}