Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how MIX subtractions works with "packed" words

Tags:

assembly

taocp

Im reading the Knuth's book TAOCP. And im just learning a simple math operations with registers. And there is an example of subtraction operation:

rA before: - | 1234 | 0| 0| 9
Cell 1000: - | 2000 |  150| 0
SUB 1000    
rA after:  + | 766  | 149 | ?

i understand that -1234-(-2000) = 766 but how (0 | 0) - 150 = 149 ??

and why 9 - 0 = ?

These are "packed" words. And maybe i need to read more about them. Or can anyone explain ?

like image 277
RusAlex Avatar asked Nov 08 '25 19:11

RusAlex


1 Answers

I believe the logic goes like this:

  • This MIX machine is a decimal machine; each byte holds two decimal digits.
  • rA contains the value - 1234 00 00 09.
  • Memory M contains the value - 2000 0150 00.
  • Subtracting M from rA using plain decimal arithmetic gives 766,014,991, or + 0766 0149 91.

Alternatively,

  • This MIX machine is a binary machine; each byte holds eight binary bits.
  • rA contains the value - 04D2 00 00 09.
  • M contains the value - 07D0 0096 00.
  • Subtracting M from rA using plain hexadecimal arithmetic gives 0x2FE0095F7, or + 02FE 0095 F7, or in decimal, + 0766 0149 247 [sic].

So, without knowing the binary/decimalness of this particular MIX machine, we can't say for certain what the low-order byte of the result will be. It is guaranteed to be the single-byte representation of -9, but whether this is 91 decimal or 0xF7 binary is unknowable.

I don't have TAOCP in front of me right now to check, but I believe this logic is a pretty good explanation of the ? that was puzzling you.

like image 176
Quuxplusone Avatar answered Nov 10 '25 22:11

Quuxplusone



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!