{"id":13,"date":"2006-06-07T00:05:39","date_gmt":"2006-06-07T08:05:39","guid":{"rendered":"http:\/\/www.pagetable.com\/?p=13"},"modified":"2006-06-07T00:05:39","modified_gmt":"2006-06-07T08:05:39","slug":"the-c-operator","status":"publish","type":"post","link":"https:\/\/www.pagetable.com\/?p=13","title":{"rendered":"The C ! operator"},"content":{"rendered":"<p>In C, the ! (&#8220;logical NOT&#8221;) operator used on a value x evaluates to 0 when x is not 0, and 1 when x is 0.  In other words, it&#8217;s equivalent to the following C:<\/p>\n<p>(x == 0) ? 1 : 0<\/p>\n<p>How should this be implemented in x86 assembly language, when &#8220;x&#8221; is already in a register?  The target register can either be the same one, or it can be a different one.  I didn&#8217;t try too hard and got 7 bytes; it can probably be made better.  On other CPUs, it can be done in a single instruction.  For example, in MIPS: &#8220;sltiu dest, src, 1&#8221;.<\/p>\n<p>Note that this is about the case where the compiler doesn&#8217;t know how the result of the ! is used, as in &#8220;return !x;&#8221; in a non-inlined function.  Cases like &#8220;if (!x)&#8221; are simpler.<\/p>\n<p>(If you want to share how easily it can be done on *your* favorite CPU, please post a comment as well!)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In C, the ! (&#8220;logical NOT&#8221;) operator used on a value x evaluates to 0 when x is not 0, and 1 when x is 0. In other words, it&#8217;s equivalent to the following C: (x == 0) ? 1 : 0 How should this be implemented in x86 assembly language, when &#8220;x&#8221; is already &#8230; <a title=\"The C ! operator\" class=\"read-more\" href=\"https:\/\/www.pagetable.com\/?p=13\" aria-label=\"Read more about The C ! operator\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-13","post","type-post","status-publish","format-standard","hentry","category-puzzle"],"_links":{"self":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/posts\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13"}],"version-history":[{"count":0,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}