2016-08-29 13 views
1

私はコースをやっていますが、私は拡張パズルの1つについています。それはマークされていないと何に向かってカウントされません。以下は8004(機械コード)以下

私はあなたの考えを思い出します。どんな(非常に)微妙なヒントもありがたいですが、私はまだそれを理解したいと思っていますが、私は打ちのめされました。

ここに質問があります。

「は、任意の二つの数字(0 255値)最初の数字が二以下であるか否かのために動作8004プログラムを書く。

を最初の番号がメモリに格納されますアドレス14で、2番目のアドレスは15番である。

最初の数値が2番目の数値より小さいか等しい場合はゼロ以外の値を、そうでない場合は0の値を出力する。

私はそれを行うために16バイトを持っています。最後の2バイトが入力番号によって占有されているからです。ここ

は、完全な命令セットである:アルゴリズムのテストの種類にCプログラムをコード化

Full instruction set and Visual

Here's my thinking: 
1. Swap second number (addr 15) and R0. Second number now loaded into R0. 
2. Swap first number and R0. Now First number is in R0, second number is in addr 14. We can keep swapping R0 and addr 14 to switch between testing the First and Second number. 
3. Check if First number is 0. 
4. If it is 0, the First number is less than or equal to second number -> print Non Zero. 
5. If it is not 0, it is unknown, and -1 from the First number for next time. 
6. SWAP First Number and Second Number 
7. Check if Second number is 0. 
8. If it is Not Zero, it's unknown, and -1 from Second number and goto 2. (SWAP again and check the first number..) 
9. If it is 0, then the first number is greater than the second number -> print 0. 
I'm fairly sure this algorithm works for all cases. BUT it won't FIT! I've tried most everything! 
My most recent thinking is along the lines of: 
14 15 - second number in R0 
14 14 - swap first and second number, use memory address 14 as cache for first/second number 
9 x - check if first number is zero, if it is zero, jump to print Not Zero (less than or equal) 
2 - minus 1 from first number, so first number -1 will be checked next time 
14 14 swap the number so second number is in R0 
8 y - check if second number does not equal zero, if it doesn't , -1 and jump to "14 14" (line 2) to swap and check first number again 
// don't know how I can -1 from R0 and jump 
7 0 if it does equal zero, print 0 (greater than) 

Can't minus 1 before checking as if it is 0, then it becomes 255 and messes up the comparison. Need to check for 0 first for both numbers. Need to check the first number first because if the second number -1 = 0 then it is is equal. So if I check second number first, then the first number -1 could equal zero meaning it is greater than or EQUAL to, which is not what we are looking for. 

Don't really know where to go from here.. 

-

#include <stdio.h> 

#define LESS_THAN_OR_EQUAL 1 
#define GREATER_THAN 0 

int main (void) { 

    int result; 

    int firstNumber = 70; 
    int secondNumber = 50; 

    // starts here 

    jump: 

    if (firstNumber == 0) { 
     result = LESS_THAN_OR_EQUAL; 
    } else { 
     firstNumber--; 

     if (secondNumber != 0) { 
      secondNumber--; 
      goto jump; 
     } else { 
      result = GREATER_THAN; 
     } 
    } 

    printf("Result: %d", result); 

    return 0; 
} 

答えて

0

はい!私はついにそれを得ました!

キーは、別の場所にジャンプした場合に数値が2バイトの命令としてどのように再解釈されるかを調べることでした。他に誰かが詰まっているなら、ヒントがあります。あなたのジャンプを見てください!