2016-05-13 3 views
0

Wenn ich versuche, den Inhalt eines Registers mit Trap-Task 17 anzuzeigen, bekomme ich einige seltsame Fehler. Hier ist mein Code:Easy 68k Fehler, wenn Trap-Befehl aufgerufen wird

*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 

Als ich das laufen lasse, erhalte ich diese Ausgabe: Output

Bundesstaat Register vor der Falle Aufruf: Before Trap

Jede Hilfe würde geschätzt.

Antwort

1

Ihr Code missbraucht die Falle. Trap # 15 ruft eine Operation auf, die durch d0 angezeigt wird, siehe die Hilfeanleitung. Sie waren auf der Suche nach Fall 15 Betrieb 3,

"Anzeigenummer in D1.L in dezimal in kleinstem Bereich unterzeichnet. (Siehe Aufgabe 15 & 20)"

Zu der Zeit Fall # 15 genannt, ist Ihre D0 $ 1400, in dem unteren Byte 0x00 ist, die als

„Anzeige n Zeichen der Zeichenkette an (A1) interpretiert wird, n D1.W (stoppt auf NULL oder max 255) mit CR, LF. (Siehe Aufgabe 13) "

A1 zu der Zeit ist gleich der Adresse des Bytes "Produkt".

Es versucht, die Zahl als c-Stil Zeichenfolge zu interpretieren, und gibt Ihnen als Ergebnis Müll.

Denken Sie auch daran, dass Ihre d0 oder d1/etc sich möglicherweise geändert haben, wenn Sie den Trap aufrufen. Versuchen Sie IMMER, die d0-Zuweisung so kurz wie möglich zu halten, um seltsame Dinge zu vermeiden. bereite zuerst deine Informationen vor, setze dann d0 und dann trap.

Das ist meistens die einzige Sache, die es daran hindert zu arbeiten, aber ich formatiere es trotzdem in einer Weise, mit der ich mich wohler fühle.

;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

Vielen Dank für die Hilfe Mann – RagCity

Verwandte Themen