如何在LC-3中打印换行符?

时间:2016-03-24 08:22:01

标签: assembly

基本上,我有输入打印结果并循环回到开头,问题是它在当前行上保持打印而不是在新行上打印结果...我该怎么做才能解决这个问题?

我想我花了2个小时试图找出方法。我已经尝试了从.fill到.stringz的所有内容,并在R0中无处不在地使用随机内容放置

实际问题: 我不确定它是否是代码中的逻辑错误,它还打印了以前印刷的东西......基本上我的输出是:

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>

应该是:

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

代码:

.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

2 个答案:

答案 0 :(得分:1)

好的,我想我更了解你要做的事情。

您需要做的就是确保R0包含值“10”(如果使用十六进制,则为“A”),然后使用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

除此之外,我需要查看代码来帮助调试它。从我可以告诉你的R0指向你的'请输入数字:'字符串,打印,然后打印'0001'。您的字符串末尾的空字符可能被'0001'的开头替换,因此它是一个连续的。但这都是猜测。

答案 1 :(得分:1)

发现问题,看起来当您尝试打印新行字符时,您需要将R0的指针值加载到R0时需要ascii值10个存储在PUTc中。之后,您需要使用.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 命令打印单个字符。我在下面做了一些小改动,现在按预期工作了。

<?php
$termsTextarea = get_queried_object();

$args = array(
    'post_type' => 'support-team-doc',
    'tax_query'=>
        array(
           array(
               'taxonomy' => 'support_team_docs',
               'field' => 'slug',
               'terms' => $termsTextarea->slug,
               'include_children' => false
           )
        )
);
$query1 = new WP_Query( $args );
while ( $query1->have_posts() ) : $query1->the_post(); 

    get_template_part( 'content', 'support_team_docs' );

endwhile; ?>