比较 2 个寄存器,每个寄存器包含一个字符 LC-3 汇编

Comparing 2 registers, each containing a character LC-3 Assembly

所以我是第一次学习 LC-3 机器的装配,所以我在这方面还是个新手。我试图让我的程序读入 2 个字符,比较它们,然后输出较小的字符。到目前为止,我所做的是将第一个字符存储在寄存器 1 中,将第二个字符存储在寄存器 2 中。然后,我想减去 ASCII 值,如果结果 < 0,则第一个字符会更小,如果> 0 则第二个会更小,如果它 = 0,则它们将是相同的字符。

我的问题是我不知道如何减去寄存器中的 2 个字符。我试过在线搜索,查看我的笔记,但找不到任何东西来回答我的问题。到目前为止,这是我的代码:

.orig x3000
LEA R0, msg ;loads message into R0
PUTS    ;puts message to screen

GETC    ;reads a char
OUT ;puts char to screen
ADD R1, R1, R0  ;R1 <- R0

LEA R0, msg ;loads message into R0 again
PUTS    ;puts message to screen
GETC    ;reads another char
OUT ;puts char to screen
ADD R2, R2, R0  ;R2 <- R0

ADD R1, R1, -R2 ;subtract second character from first character
                ;This line here is my problem!!!!

BRP elseif  ;if it's positive, the second character is larger
BRZ else    ;if it's zero, they are the same

if  
    LEA R0, msg2    ;loads second message
    PUTS    ;puts second message on screen
    AND R0, R0, #0  ;clears R0
    ADD R0, R0, R1  ;R0 <- R1
    OUT ;print the first char
    br endif

elseif  
    LEA R0, msg2    ;loads second message
    PUTS    ;puts second message on screen
    AND R0, R0, #0  ;clears R0
    ADD R0, R0, R2  ;R0 <- R2
    OUT ;print the second char
    br endif

else    
    LEA R0, msg3    ;loads third message
    br endif

endif

    HALT

msg .STRINGZ "\nEnter any character: "
msg2    .STRINGZ "\nThe smallest character is: "
msg3    .STRINGZ "\nThe characters are the same."
    .END

请记住,这就像是我有史以来的第一个汇编程序,所以它可能超级可怕。 ^_^" 但是因为我还在学习,所以我想保持简单和直接,即使这是一种愚蠢的实现方式。

所以我的中断语句之前的那一行是我遇到问题的地方。如上所示,我尝试添加寄存器 1 和寄存器 2 的负值,但这没有用,所以基本上我的问题是,有没有办法 subtract/compare 两个 char 值存储在 2 个寄存器中??

任何 help/advice 将不胜感激!! :)

没有直接的运算符可以使用 LC3 进行减法。您需要使用 2 的补码。

R1 = R2-R3;  //This is not possible.
// using 2's Complement method
R1 <- NOT R3;
R1 <- R1+1;
R1 <- R2+R1;

寄存器R1会有减法结果。您可以使用比较代码打印出较小的数字