2016-03-24 8 views
0

Im Grunde habe ich eine Eingabe, die ein Ergebnis ausgibt und zurück zum Anfang springt, das Problem ist, dass es auf der aktuellen Zeile druckt, anstatt das Ergebnis auf der neuen Zeile zu drucken ... was könnte ich tun, um das zu beheben?Wie wird ein neues Zeilenzeichen in LC-3 gedruckt?

Ich denke, ich habe 2 Stunden damit verbracht, herauszufinden, wie. Ive versuchte alles von .fill zu .stringz und gedankenlos mit Puts überall mit zufälligen Sachen in R0

Tatsächliches Problem: Ich bin nicht sicher, ob es ein logischer Fehler im Code, der auch das vorherige, was gedruckt wurde, druckt ... im Grunde, was passiert ist meine Ausgabe lautet:

Please enter digit: 1 <---- assume thats input 
Please enter a digit: 0001 
Please enter a digit: Please enter a digit 4 
Please enter a digit: 0100 
Please enter a digit: Please enter a digit: <wait for user input> 

Wenn es sein sollte:

Please enter digit: 1 <---- assume thats input 
0001 
Please enter a digit 4 
0100 
Please enter a digit <wait for user input> 

Code:

.orig x3000 

start AND R0, R0, #0 
    AND R1, R1, #0 
    AND R2, R2, #0 
    AND R3, R3, #0 
    AND R4, R4, #0 
    AND R5, R5, #0 
    AND R6, R6, #0 
    AND R7, R7, #0 

lea r0, prompt 
puts 
lea r1, input 

char getc 
putc 
str r0, r1, #0 
add r1, r1, #1 
add r2, r0, #0 

ld r3, check1  ;first check 
add r2, r2, r3 



add r4, r0, #0 
add r5, r2, #0 
and r2, r2, #0 
getc 
add r2, r0 #-10 
brz cont 


cont and r0, r0, #0 
and r2, r2, #0 
add r0, r4, #0 
add r2, r5, #0 

brn incorrect 

and r2, r2, #0 
add r2, r0, #0 
and r3, r3, #0 

ld r3, check2  ;second check 
add r2, r2, r3 
brzp incorrect 

add r4, r0, #0 
and r0, r0, #0 
and r2, r0, #0 
add r2, r2, #10 

body and r0, r0 #0 
add r0, r4, #0 
and r2, r2, #0  ;numbers 0-9 that make it pass checks 
and r3, r3, #0 
ld r3, test0 
add r2, r0, r3 
brz case0 

and r2, r2, #0 
and r3, r3, #0 
ld r3, test1 
add r2, r0, r3 
brz case1 

and r2, r2, #0 
and r3, r3, #0 
ld r3, test2 
add r2, r0, r3 
brz case2 

and r2, r2, #0 
and r3, r3, #0 
ld r3, test3 
add r2, r0, r3 
brz case3 

and r2, r2, #0 
and r3, r3, #0 
ld r3, test4 
add r2, r0, r3 
brz case4 

and r2, r2, #0 
and r3, r3, #0 
ld r3, test5 
add r2, r0, r3 
brz case5 

and r2, r2, #0 
and r3, r3, #0 
ld r3, test6 
add r2, r0, r3 
brz case6 

and r2, r2, #0 
and r3, r3, #0 
ld r3, test7 
add r2, r0, r3 
brz case7 

and r2, r2, #0 
and r3, r3, #0 
ld r3, test8 
add r2, r0, r3 
brz case8 

and r2, r2, #0 
and r3, r3, #0 
ld r3, test9 
add r2, r0, r3 
brz case9 

test0  .fill -48 
case0  lea r0, empty 
    puts 
    lea r0, eol 
    puts 
    lea r0, string0 
    puts 
    lea r0, eol 
    puts 
    brnzp start 

test1  .fill -49 
case1  lea r0, eol 
    puts 
    lea r0, string1 
    puts 
    lea r0, eol 
    puts 
    brnzp start 

test2  .fill -50 
case2  lea r0, eol 
    puts 
    lea r0, string2 
    puts 
    lea r0, eol 
    puts 
    brnzp start 

test3  .fill -51 
case3  lea r0, eol 
    puts 
    lea r0, string3 
    puts 
    lea r0, eol 
    puts 
    brnzp start 

test4  .fill -52 
case4  lea r0, eol 
    puts 
    lea r0, string4 
    puts 
    lea r0, eol 
    puts 
    brnzp start 

test5  .fill -53 
case5  lea r0, eol 
    puts 
    lea r0, string5 
    puts 
    lea r0, eol 
    puts 
    brnzp start 

test6  .fill -54 
case6  lea r0, eol 
    puts 
    lea r0, string6 
    puts 
    lea r0, eol 
    puts 
    brnzp start 

test7  .fill -55 
case7  lea r0, eol 
    puts 
    lea r0, string7 
    puts 
    lea r0, eol 
    puts 
    brnzp start 

test8  .fill -56 
case8  lea r0, eol 
    puts 
    lea r0, string8 
    puts 
    lea r0, eol 
    puts 
    brnzp start 

test9  .fill -57 
case9  lea r0, eol 
    puts 
    lea r0, string9 
    puts 
    lea r0, eol 
    puts 
    brnzp start 

string0  .stringz "0000" 
string1  .stringz "0001" 
string2  .stringz "0010" 
string3  .stringz "0101" 
string4  .stringz "0100" 
string5  .stringz "0101" 
string6  .stringz "0110" 
string7  .stringz "0111" 
string8  .stringz "1000" 
string9  .stringz "1001" 


empty  .fill 0 
eol  .fill 10 
prompt  .stringz "Enter a digit: " 
check1  .fill -48 
check2  .fill -58 
incorrect halt 
input  .blkw 10 

.end 
+0

Suchen Sie den Newline-Hexcode des Betriebssystems und drucken Sie das? –

+3

Durch das Entfernen des Codes wird die Antwort ungültig. Das ist verpönt. Bitte tu das nicht. – rene

+0

Rene, ich habe meinen Code absichtlich entfernt, wäre es möglich, wenn Sie es ebenso wie Chris Antwort, die meinen Code enthält, freundlicherweise abnehmen könnten? oder zumindest Fragmente davon, ich könnte in ernsthafte Schwierigkeiten mit der Universität geraten, ich wollte nur winzige Hilfe mit einem Druckfehler, aber das Posten meines Codes kann ein ernsthafter Verstoß sein. –

Antwort

1

Ok, ich denke, ich verstehe besser, was Sie versuchen zu tun.

Alles, was Sie tun müssen, ist sicherzustellen, dass R0 den Wert enthält ‚10‘ (oder ‚A‘, wenn Sie mit hex arbeiten) und dann ausdrucken mit putc

.ORIG x3000 

    LD R0, ENDLINE  ; R0 = the value of ENDLINE 
    PUTc    ; Prints the char in R0 
    TRAP x25   ; halt 

; data segment 
ENDLINE .FILL x0A  ; A decimal 10, or a hex 'A' 
.END 

Andere Dann müsste ich den Code sehen, um ihn zu debuggen. Von dem, was ich Ihnen sagen kann, zeigen Sie R0 auf Ihre 'Bitte geben Sie eine Ziffer:' Zeichenfolge, Drucken, und dann Drucken der '0001'. Es ist möglich, dass Ihr Null-Zeichen am Ende Ihrer Zeichenfolge durch den Anfang von '0001' ersetzt wurde, und es handelt sich also um eine Fortsetzung. Aber das ist alles Spekulation.

1

das Problem gefunden, es sieht aus wie wenn Sie versuchen, eine neue Zeile drucken char Sie den Zeigerwert von eol in R0 geladen sind, wenn Sie auf ascii-Wert von 10 in R0 gespeichert müssen. Danach müssen Sie den Befehl PUTc verwenden, um ein einzelnes Zeichen zu drucken. Ich habe diese kleinen Änderungen unten vorgenommen und jetzt funktioniert es wie erwartet.

.

.orig x3000 

start AND R0, R0, #0 
AND R1, R1, #0 
AND R2, R2, #0 
AND R3, R3, #0 
AND R4, R4, #0 
AND R5, R5, #0 
AND R6, R6, #0 
AND R7, R7, #0 

lea r0, prompt 
puts 
lea r1, input 

char getc 
putc 
str r0, r1, #0 
add r1, r1, #1 
add r2, r0, #0 

ld r3, check1; first check 
add r2, r2, r3 



add r4, r0, #0 
add r5, r2, #0 
and r2, r2, #0 
getc 
add r2, r0 # - 10 
brz cont 


cont and r0, r0, #0 
and r2, r2, #0 
add r0, r4, #0 
add r2, r5, #0 

brn incorrect 

and r2, r2, #0 
add r2, r0, #0 
and r3, r3, #0 

ld r3, check2; second check 
add r2, r2, r3 
brzp incorrect 

add r4, r0, #0 
and r0, r0, #0 
and r2, r0, #0 
add r2, r2, #10 

body and r0, r0 #0 
add r0, r4, #0 
and r2, r2, #0; numbers 0 - 9 that make it pass checks 
and r3, r3, #0 
ld r3, test0 
add r2, r0, r3 
brz case0 

and r2, r2, #0 
and r3, r3, #0 
ld r3, test1 
add r2, r0, r3 
brz case1 

and r2, r2, #0 
and r3, r3, #0 
ld r3, test2 
add r2, r0, r3 
brz case2 

and r2, r2, #0 
and r3, r3, #0 
ld r3, test3 
add r2, r0, r3 
brz case3 

and r2, r2, #0 
and r3, r3, #0 
ld r3, test4 
add r2, r0, r3 
brz case4 

and r2, r2, #0 
and r3, r3, #0 
ld r3, test5 
add r2, r0, r3 
brz case5 

and r2, r2, #0 
and r3, r3, #0 
ld r3, test6 
add r2, r0, r3 
brz case6 

and r2, r2, #0 
and r3, r3, #0 
ld r3, test7 
add r2, r0, r3 
brz case7 

and r2, r2, #0 
and r3, r3, #0 
ld r3, test8 
add r2, r0, r3 
brz case8 

and r2, r2, #0 
and r3, r3, #0 
ld r3, test9 
add r2, r0, r3 
brz case9 

test0.fill - 48 
case0 
ld r0, eol 
putc 
lea r0, string0 
puts 
ld r0, eol 
putc 
brnzp start 

test1.fill - 49 
case1  ld r0, eol 
putc 
lea r0, string1 
puts 
ld r0, eol 
putc 
brnzp start 

test2.fill - 50 
case2  ld r0, eol 
putc 
lea r0, string2 
puts 
ld r0, eol 
putc 
brnzp start 

test3.fill - 51 
case3  ld r0, eol 
putc 
lea r0, string3 
puts 
ld r0, eol 
putc 
brnzp start 

test4.fill - 52 
case4  ld r0, eol 
putc 
lea r0, string4 
puts 
ld r0, eol 
putc 
brnzp start 

test5.fill - 53 
case5  ld r0, eol 
putc 
lea r0, string5 
puts 
ld r0, eol 
putc 
brnzp start 

test6.fill - 54 
case6  ld r0, eol 
putc 
lea r0, string6 
puts 
ld r0, eol 
putc 
brnzp start 

test7.fill - 55 
case7  ld r0, eol 
putc 
lea r0, string7 
puts 
ld r0, eol 
putc 
brnzp start 

test8.fill - 56 
case8  ld r0, eol 
putc 
lea r0, string8 
puts 
ld r0, eol 
putc 
brnzp start 

test9.fill - 57 
case9  ld r0, eol 
putc 
lea r0, string9 
puts 
ld r0, eol 
putc 
brnzp start 

string0.stringz "0000" 
string1.stringz "0001" 
string2.stringz "0010" 
string3.stringz "0101" 
string4.stringz "0100" 
string5.stringz "0101" 
string6.stringz "0110" 
string7.stringz "0111" 
string8.stringz "1000" 
string9.stringz "1001" 


empty.fill 0 
eol.fill x0A 
prompt.stringz "Enter a digit: " 
check1.fill - 48 
check2.fill - 58 
incorrect halt 
input.blkw 10 

.end 
Verwandte Themen