Test20130315
0        LD R1, A
1        ST R5, B
2        ADD R2, R1, R5
3        RET
4    A:    WORD 3
5    B:    WORD 5

6        XOR R1, R2, R6
7        SHL R1, 10
8    LOOP:    MOV R3, R1
9        CMP R3, R5
10        JGT LOOP
11        RET
12    C:    WORD 37
13    D:    BYTE 25

14        LBR R1, R3+20
15        LDI R8, 100
16        ST  R5, C
17        STB R13, A 
18        RET

解答

位址        程式                    絕對定址         相對於 PC 定址

0000        LD R1, A        00100010         001F000C
0004        ST R5, B        01500014    015F000C
0008        ADD R2, R1, R5        13215000
000C        RET            2C000000
0010    A:    WORD 3            00000003
0014    B:    WORD 5            00000005

0018        XOR R1, R2, R6        1A126000
001C        SHL R1, R2, 10         1E12000A
0020    LOOP:    MOV R3, R1        12310000
0024        CMP R3, R5        10350000
0028        JGT LOOP        23FFFFF4        23FFFFF4 (沒有絕對版)
002C        RET            2C000000

0030    C:    WORD 37            00000025
0034    D:    BYTE 25            19
0035        LBR R1, R3+20        06130014
0039        LDI R8, 100        08800064
003D        ST  R5,  C        01500030    015FFFEF
0041        STB R13, A         03D00010    03DFFFCB
0045        RET            2C000000

2 補數的計算過程

-12 = -C    001100 => 110011 + 1 => 1111110100 =>        FFFFF4

     -11    00010001 => 11101110 + 1 => 11101111 =>        FFEF

     -35    00110101 => 11001010 + 1 => 11001011 =>        FFCB
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License