1

私は Knuth のThe Art of Computer Programmingに取り組んでいますが、MIX アセンブリ言語、特に DIV 演算子について質問があります。

133 ページで、彼は DIV 演算子がどのようにアキュムレータと拡張レジスタに影響を与え、これらのレジスタと入力メモリ セルの特定の状態が与えられるかの例を示します。質問は、このスタック オーバーフローの投稿で説明されています (そして答えられていると思います): How does division work in MIX?

私の問題は、答えた人が、rAX (レジスタ A と X) に格納されている 10 バイトの単語の値を、私が理解できない方法を使用して単一の数値に変換したことです。

手で除算を行う場合、バイトを単一の数値に変換すると、-210,501,825 が得られます (最小の種類のバイトを使用している場合 - Knuths book では 6 ビット (!))。

誰かがこの変換について教えてくれますか?

ありがとう、サム

4

1 に答える 1

2

It depends on the byte size that you're using. Knuth deliberately leaves the underlying implementation of bytes undefined - each byte can support anywhere from 64 to 100 underlying values, but the minimum is 64, and that's what most implementations seem to use.

Let's say each byte holds 64 values, and say you have the following register contents in rA:

+ 01 02 03 04 05

The least significant byte is on the right hand side. Therefore, the "overall" value of the entire rA register would be:

= (1 * 64^4) + (2 * 64^3) + (3 * 64^2) + (4 * 64^1) + (5 * 64^0)
= (1 * 16777216) + (2 * 262144) + (3 * 4096) + (4 * 64) + (5 * 1)
= 17314053

That's exactly what GNU MDK will give you:

MIX> weval 1(1:1),2(2:2),3(3:3),4(4:4),5(5:5)
+ 01 02 03 04 05 (0017314053)

For rAX (rA and rX considered as one register), it's the same idea, except you put rA to the left of rX. So if you have:

rA = + 01 02 03 04 05
rX = + 06 07 08 09 10

The overall value would be:

(1 * 64^9) + (2 * 64^8) + (3 * 64^7) + (4 * 64^6) + (5 * 64^5) +
(6 * 64^4) + (7 * 64^3) + (8 * 64^2) + (9 * 64^1) + (10 * 64^0)

For a decimal implementation, you would just use 100 instead of 64 as the base. So in the initial example, you would end up with:

= (1 * 100^4) + (2 * 100^3) + (3 * 100^2) + (4 * 100^1) + (5 * 100^0)
= 102030405

Hope that helps.

于 2016-08-31T01:39:24.983 に答える