Toggle search
Search
Toggle menu
notifications
Toggle personal menu
Editing
Basic Assembly Programming
(section)
From Turing Complete
Views
Read
Edit
Edit source
View history
associated-pages
Page
Discussion
More actions
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===== Complex Operations From Simple Ones (XOR) ===== We can break the XOR operation into smaller steps. Recall that the XOR of <code>a</code> and <code>b</code> is <code>a ^ b = (a | b) & ~(a & b)</code>. In words, the XOR of two bits is 1 if their OR is 1, ''and'' their AND is 0. We have OR and NAND operations, so we can do these things. We need to save some intermediate values while we’re working. We’ll use register 0 since it’s free. Notice how we shuffle data around into the correct registers as needed. <pre>move|s4|d1 # the value we saved earlier move|s3|d2 # the mask we just computed or # their bitwise OR move|s3|d0 # save that so it isn't overwritten by... nand # their bitwise NAND move|s0|d1 # prepare to operate on their OR... move|s3|d2 # and their NAND... and # the result of the XOR.</pre> Now we have the bitwise complement of the value that was in register 0. It’s in register 3, but from here we could move it wherever we want. <span id="control-flow"></span>
Summary:
Please note that all contributions to Turing Complete are considered to be released under the Creative Commons Attribution-ShareAlike (see
TuringComplete:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)