2016-05-13 119 views
0

當我嘗試使用陷阱任務17顯示寄存器的內容時​​,出現一些奇怪的錯誤。 這裏是我的代碼:調用trap命令時容易發生68k錯誤

*Equates section 
program_start equ $1000 *Start Location of program 
timesToAdd equ 10  *Number to multiply numToMultiply by 
numToMultiply equ 512 *Number to multiply through cumulative sum 

ORG program_start 
START:     ; first instruction of program 

* Put program code here 
    MOVE.L #$00000000,D0 *Initially set value in D0 to 0 
    MOVE.B #timesToAdd,D2 *Store times left to add in D2 

loop CMP.B #0,D2   *Check if we are finished adding 
     BEQ loop_end   *exit loop if we are done 
     SUB.B #1,D2   *decrement timesToAdd by 1 
     ADDI.L #numToMultiply,D0 *Add numToMultiply to value in D0 
     BCC skipSet 
     MOVE.B #1,D1   *Set D1 to 1 if carry bit is set 
skipSet BRA loop 
loop_end  
    MOVE.L D0,D2 
    MOVE.L #17,D0 

    CMP.B #0,D1 *Check if there was a carry 
    BEQ skipCarry 
    LEA Carry,A1 
    Trap #15  *Print Carry: with carry bit 
skipCarry 
    MOVE.L D2,D1 
    LEA Product,A1 
    Trap #15 

    SIMHALT    ; halt simulator 

Carry DC.B 'Carry: ' 
Product DC.B 'Product= ' 
    END START  ; last line of source 

當我跑,我得到這樣的輸出: 寄存器Output

國家陷阱調用之前: Before Trap

任何幫助,將不勝感激。

回答

1

你的代碼可怕地誤用陷阱。陷阱#15調用d0指示的操作,請參閱幫助手冊。你要找的陷阱15操作3,

「顯示簽約數量D1.L在最小的領域小數。(見任務15 & 20)」

當時陷阱#15叫,你的D0爲$ 1400中,其中較低的字節爲0x00,這是在(A1)解釋爲

「的字符串的顯示n個字符,n是D1.W(停止在NULL或最大255)與CR, LF。(見任務13)「

當時的A1等於字節「Product」的地址。

它試圖將數字解釋爲一個c風格的字符串,並給你垃圾作爲結果。

另外,請記住,在您調用陷阱時,您的d0或d1/etc可能已經更改。總是儘量保持d0的分配儘量靠近陷阱電話,以避免奇怪的事情發生。首先準備好你的信息,然後設置d0,然後調用陷阱。

這主要是阻止它工作的唯一的東西,但我重新設置了它的格式,讓我更舒適。

;Equates section 
program_start equ $1000  ; Start Location of program 
timesToAdd equ 10   ; Number to multiply numToMultiply by 
numToMultiply equ 512   ; Number to multiply through cumulative sum 

    org program_start 
start:      ; first instruction of program 
    move.l #$00000000, D0 ; Initially set value in D0 to 0 
    move.b #timesToAdd, D2 ; Store times left to add in D2 

loop: 
    cmp.b #0, d2    ; Check if we are finished adding 
    beq loop_end   ; exit loop if we are done 
    sub.b #1, d2    ; decrement timesToAdd by 1 
    addi.l #numToMultiply, d0 ; Add numToMultiply to value in D0 
    bcc skipSet 
    move.b #1, d1    ; Set D1 to 1 if carry bit is set 

skipSet: 
    bra loop 

loop_end: 
    ; Check if there was a carry 
    cmp.b #0, d1  
    beq skipCarry 
    lea Carry, a1 

    ; Print Carry: with carry bit 
    move.l #17, d0 
    move.l d0, d2 
    trap #15  

skipCarry: 
    move.l d2, d1 
    lea Product, a1 

    move.l d0, d1 
    move.l #3, d0 
    trap #15 

    simhalt 

Carry dc.b 'Carry: ' 
Product dc.b 'Product= ' 
    end start 
+0

非常感謝幫忙的人 – RagCity

相關問題