1.3.1

1.3.1

14. For each MIX operation, consider whether there is a way to set the ±AA, I, and F portions so that the result of the instruction is precisely equivalent to NOP(except that the execution time may be longer). Assume that nothing is known about the contents of any registers or any memory locations. Whenever it is possible to produce a nop, state how it can be done. Examples: INCA is a no-op if the address and index parts are zero. JMP can never be a no-op, since it affects rJ.

ans.

1)      nop with nothing;

2)      add, sub

a)     with F = (0:0);

b)    with AA = *, F=(3:3);

3)      hlt;

4)      any shift with M=0;

5)      slc or src with I=0, AA=10k;

6)      move with F=0;

7)      stj *(0:0);

8)      stz *(0:0);

9)      stz *(3:3);

10)   jsj *+1;

11)   any inc, dec with M=0.

16. Write a program that sets memory cell 0000-0099 all to zero and is (a) as short a program as possible;(b)as fast a program as possible.

sol.

(a)      total 100 words.

op           add                time

stz           0                   2

ent1        1                   1

move      0(50)             101

move      0(49)             99

 

T = (2+1+101+99)u=203u.

(b)

        stz            0                  2

        stz           1                   2

        ...            ...                  2

        stz            99                2

 

       T=200u.

17. This is the same as the previous exercise, except that location 0000 through N, inclusive, are to be set to zero, where N is the current content of rI2. Your program (a) and (b) should work for any value 0≤N≤2999; they should start in location 3000.

sol.

(a)

3000       stz          0,2

3001       dec2       1

3002       j2nn        3000

(b)我自己写的:

loc          op           add                times                                                 remarks

3000       stz           0                   1

3001       ent1        1                   1

3002       dec2       63                 ceil( N/63 )

3003       j2n         3006              ceil( N/63 )

3004       move      0(63)             ceil ( N/63 )

3005       jmp        3002              ceil ( N/63 )

3006       inc2        63                  1

3006       st2          3008(4:4)       1

3008       move      0                    1                                                     有可能move 0(0)

answer is:

loc          op           add                times                                                 remarks

3000       stz          0                     1

3001       ent1        1                    1                                                     

3002       jmp         3004              1

3003       move      0(63)             ceil( N/63 )-1

3004       dec2       63                  ceil( N/63 )-1

3005       j2p         3003              1                                                     

3006       inc2        63                  1

3007       st2          3008(4)         1

3008       move      0                    1                                                      有可能move 0(63)

与答案相比,指令条数相等,但是耗时较多。因为我用了j2n,用了绝对跳转jmp,导致主循环有4条,答案只有3条。

18. After the following “number one” program has been executed, what changes to registers, toggles, and memory have taken place?

op           add                remarks

stz           1                   mem[1] <- (+0)                  

 mem[1]:  + 0 0 0 0 0

 

ennx        1                   rX <- (-1)                           

 rx:          - 0 0 0 0 1

 

stx          1(0:1)            mem[1]:  - 1 0 0 0 0

 

slax         1                   rA:          ± x x x x 0    

 rX:          - 0 0 0 1 0

 

enna        1                   rA <- (-1)                           

 rA:          - 0 0 0 0 1

 

incx        1                    rX:          - 0 0 0 0 max(99, 63, ...)

 

ent1        1                   rI1 <- (+1)

 

src          1                   rA:          - max 0 0 0 0       

rX:          - 1 0 0 0 0

 

add         1                  mem[1]:  - 1 0 0 0 0            

mem[1]+rA: overflow toggle.

rA<- (-0)

 

dec1        -1               rI1 <- 2

 

stz          1                   mem[1] <- (+0)

 

cmpa      1                   mem[1] = +0, rA = -0.

                                   EQ

 

move      -1,1(1)          M <- rI1 – 1 = 2 – 1 = 1, rI1 = 2,

                                   mem[2] <- mem[1] = +0, rI1 <- 3.

 

num        1                   rA:         - 0 0 0 0 0

                                   rX:         - 1 0 0 0 0

ð        rA <- -10000.(num不改变sign)

char        1                   rA:          - 30 30 30 30 30

                                   rX:          - 31 30 30 30 30

 

总之:

rA:         - 30 30 30 30 30

rX:         - 31 30 30 30 30

rI1:         3

overflow: toggled.

EQUAL:        toggled.

mem[1]:         0

mem[2]:         0

20. Write a program that sets all 4000 memory cells equal to a “hlt” instruction and then stops.

sol.

loc                 op           add                       times              remarks

3005              ent1        0                          1

3006              move      3999(1)                1                    1

3007              move      0(43)                    93                  43*93=3999

                      jmp         3007                    93

3009              hlt           0                         

其实大块的move时,会重复地set 3009,但是,如果用3998代替39993998=2*19991999是素数,无法再分解了,只好用3999

T = 8188u.

这里没有要求最短或最快,不过这个algo很有启发意义。

最快的是全hltprog,像是耍赖皮。

还想到的一种是增大每次move的数据量,那自然也不能用3999,就用4000=50*80,减少了move次数,只重复设置了1个位置:3949

loc                 op           add                       times              remarks

3043             ent1        3950                     1

                     move      3949(50)               1

                     ent1        0                           1

                     move      3949(50)               1

3047             move     0(50)                      78

                     jmp        3047                      78

3049             hlt           0

T = 8160u.仅仅快28u

21. (a) Can the rJ ever be zero? (b) Write a program that, given a number N in rI4, set register J equal to N, assuming that 0<N≤3000. Your program should start in location 3000. When your program has finished its execution, the contents of all memory cells must be unchanged.

(a) rJ不能为零,即使令rJ溢出,获得的值也是undefined,不是0

(b)

3000       lda          -1,4

3001       ldx          3004

3002       stx          -1,4

3003       jmp         -1,4

3004       jmp         3005

3005       sta          -1,4

22. Location 2000 contains an integer number, X. Write two programs that compute X13 and halt with the result in register A. One program should use the minimum number of MIX memory locations; the other should require the minimum execution time possible. Assume that X13fits into a single word.

(a)minimum space. 这个简单些

3000      ent1        12

              lda          2000

3002      mul         2000

              slax         5

              dec1       1

              j1p          3002

              hlt            0

(b)minimum execution time. 这个有时想不到,就是建表。

|X13|1010 XZ => X{0,±1, ±2, ±3, ±4, ±5}

3000    ld1     2000

3001    lda     3500,1

3002    hlt     0

 

3495       (-5)^13

3496       (-4)^13

3497       (-3)^13

3498       (-2)^13

3499       (-1)^13

3500       0

3501       1^13

3502       2^13

3503       3^13

3504       4^13

3505       5^13

 

23. Location 0200 contains a word

+ a b c d e

write two programs that compute the “reflect” word

+ e d c b a

and halt with the result in register A. One program should do this without using MIX’s ability to load and store partial fields of words. Both programs should take minimum possible number of memory locations under the stated conditions(including all locations used for the program and for temporary storage of intermediate results).

无他,就是反复移位。

ans.                                                 

3000       ent1        4                         

3001       lda         0200                    

              sra          0,1                       

              srax        1                         

              dec1       1

              j1nn        3001

              slax         5

3007      hlt           0

注意,循环移位只能针对rAX的移位,没有单独对rArX的循环移位。

24. Assuming that registers A and X contain

+ 0 a b c d      and         + e f g h i

respectively, write two programs that change the contents of these registers to

+ a b c d e      and         + 0 f g h i

respectively, using (a) minimum memory space and (b) minimum execution time.

sol.

(a) minimum space. 在本题中其实不一定最短,但很有启发。。

ent1        +10000

st1          3500

div          3500

(b)      minimum execution time. 注意,没有单独对rX进行移位的指令。

src          4

sla          1

src          5

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值