1

我想将最大数字的地址存储在 HL 中,但我真的不知道该怎么做 这是我到目前为止所做的

   0000 LXI H,3000H       ;Load H-L pair with address 3000H
   0001
   0002
   0003 MOV E,M      ;Move counter from memory to reg. E.
   0004 INX H        ;Increment H-L pair
   0005 MOV A,M      ;Move the 1st number from memory to reg. A.
   0006 DCR E        ;Decrement counter.
   0007 INX H        ;Increment H-L pair
   0008 MOV D,M      ;Move the next number from memory to reg. D.
   0009 CMP D        ;Compare D with A.
   000A JNC 000EH    ;Jump to address 000EH if there is no carry
   000B
   000C
   000D MOV A,D      ;Move largest from reg. D to reg. A.
   000E DCR E        ;Decrement counter.
   000F JNZ 0007H    ;Jump to address 0007H if counter is not zero.
   0010
   0011
   0012 INX H        ;Increment H-L pair.
   0013 MOV C,A      ;Move the result from reg. A to C
   0014 HLT


**MEMORY**  
3000H: 05 (counter)
3001H: 2C
3002H: 1E
3003H: 58
3004H: 46
3005H: 53

该代码在查找最大数的部分工作正常,但我想要的是将最大数的地址最后存储在 HL 中

4

1 回答 1

1

I don't know 8085 very well so I'll just give a general answer that works for any register machine. (Or in C or whatever: this is one of those questions where the answer is "the same as you would in any other language")

When you find a new maximum, copy the address somewhere as well as the value. (In the same block of instructions with MOV A,D, which you conditionally jump over). You still need the value for comparisons.

If 8085 doesn't have enough registers, store it to memory. When your loop is done, you can reload HL from there if / when you want. Of leave the value in memory as the result of your function.

Make sure you init both the starting value and address to the first element, in case it's the max. Unlike a value-only search, you can't just use the minimum possible value as an initializer for the max.

于 2017-12-23T21:44:27.850 回答