3 ms·
Technically, it should say it lacks built-in arithmetic instructions. Any processor can add, subtract, multiply, or fixed width integers via some combination o
by pmiller2 6y ago
Technically, it should say it lacks built-in arithmetic instructions. Any processor can add, subtract, multiply, or fixed width integers via some combination of bitwise operations. For example, https://en.wikipedia.org/wiki/Bitwise_operation#Applications https://en.wikipedia.org/wiki/Bitwise_operation#Applications shows how to do unsigned addition and multiplication.
And, of course, for better or worse, "add two numbers without using the + operator" is one of those silly LeetCode trivia questions software engineers occasionally get quizzed on.
- Invictus0 6y agoI did this in my head and came up with -1*(-x - y); seems a little cheeky but acceptable.
- recursive 6y agoIf you're allowed negation, (like `-x`) then `x - (-y)` seems even better.
- egsmi 6y agoSubtract is a "built-in arithmetic instructions" so it wouldn't be allowed in this environment. The idea is to implement arithmetic, but from bitwise operations. https://en.wikipedia.org/wiki/Bitwise_operation https://en.wikipedia.org/wiki/Bitwise_operation
- echlebek 6y agoHere's some background on how things like that work: https://en.wikipedia.org/wiki/Adder_(electronics) https://en.wikipedia.org/wiki/Adder_(electronics)
- kens 6y agoThis is getting far afield from the actual Nanoprocessor, which has increment and decrement instructions. With those, you can add two numbers by repeatedly incrementing one and decrementing the other. (Which is a bit like addition using the Peano axioms.) See page 126 of the Nanoprocessor User's Manual for code to add two numbers in this way. https://www.hp9845.net/9845/downloads/manuals/Nanoprocessor.pdf https://www.hp9845.net/9845/downloads/manuals/Nanoprocessor....
- egsmi 6y agoOne can also use the techniques demonstrated your reversing the ALU article. :) https://www.righto.com/2020/08/reverse-engineering-8086s.html https://www.righto.com/2020/08/reverse-engineering-8086s.htm...
- recursive 6y agoInteresting problem. In this case though, I was just offering a pointless optimization to the parent post, which also used subtraction, so I assumed it was allowed.
- mkup 6y agoYes, addition and all other arithmetic and logical operations can be implemented using only one building block: Peirce's arrow (Logical NOR). I can't understand why you are getting downvoted.
- deleted 6y ago[deleted]
- 082349872349872 6y agoor, as with sed, lookup tables https://en.wikipedia.org/wiki/IBM_1620#Transferred_to_San_Jose_for_production https://en.wikipedia.org/wiki/IBM_1620#Transferred_to_San_Jo...
- perl4ever 6y agoA question I was interested in a while ago was, how would you implement the usual bitwise operations if you can only do 2s-complement arithmetic. I wasn't sure if it's something anyone reasonably bright should be able to derive, or how to search for it.