简体   繁体   English

为什么我的 MARIE 程序添加变成字母而不是数字?

[英]Why is my MARIE program addition becoming letters instead of numbers?

I am new to assembly and I'm not sure why my code isn't working.我是汇编新手,我不确定为什么我的代码不起作用。

I'm inputing and displaying in ASCII format, I can see the 1 and 3, but why isn't the addition sum showing?我用ASCII格式输入和显示,我可以看到1和3,但是为什么没有显示加法和?

My program is simply suppose to perform an addition.我的程序只是假设执行加法。 And display something like:并显示如下内容:

'>1+3=4 '>1+3=4

if the inputs are 1 and 3, then if user enters, it stops.如果输入是 1 和 3,那么如果用户输入,它就会停止。 otherwise loops back.否则循环回来。


Loop,Load    Greater
    Output      /for the ">" symbol

    Input 
    Output
    Store    X  /Taking input, storing and displaying 1st operand

    Load    Addr
    Output      /Loading and displaying "+"

    Input
    Output
    Store    Y  /Inp, str, displaying 2nd operand

    Load    Equal
    Output            /Display "="

    Load     X
    Add    Y
    Output       /Adding then displaying sum

    Input
    Store   Cond
    Skipcond     800
    Jump     Loop

    Halt

Greater,    DEC 62  
X,          DEC 0
Addr,       DEC 43
Y,        Dec 0
Equal,    Dec 61
Cond,      DEC 0```

In order to get characters like !为了得到像! , you'll need to put the simulator into input mode accepting unicode characters instead of numbers (hex/decimal/binary). ,您需要将模拟器置于接受 unicode 字符而不是数字(十六进制/十进制/二进制)的输入模式。 And of course, in order to print characters like > and = you'll need to have the output configured for unicode as well.当然,为了打印像>=这样的字符,您还需要为 unicode 配置 output。

Now that you're using ascii/unicode input & output, handling characters is the name of the game.现在您使用的是 ascii/unicode 输入和 output,处理字符就是游戏的名称。 (Multi-digit numbers are character sequences.) (多位数字是字符序列。)

The ascii digit 1 has value 49, and 3 is 51. You're adding 49 + 51 and getting 100, which is the ascii code for lower case d . ascii 数字1的值为3为 51。您将 49 + 51 相加得到 100,这是小写d的 ascii 代码。 You need to subtract one ascii 0 (which is 48) and then you'll have 52, which is ascii 4 .您需要减去一个 ascii 0 (即 48),然后您将得到 52,即 ascii 4

If you wanted the numeric value, 4, you would have to subtract 0 (48) from both input digits.如果您想要数值 4,则必须从两个输入数字中减去0 (48)。 And if you wanted to print the sum value as a digit in ascii, you'll need to add a 48 to that result.如果您想将总和值打印为 ascii 中的数字,则需要在该结果中添加 48。 In this case, that would be two subtractions of 48 and one addition of same — hence the short cut, subtract just one 48 and the digit will print.在这种情况下,这将是 48 的两个减法和一个相同的加法 - 因此捷径,仅减去一个 48 并且数字将打印。

Once you're in the mode of handling characters, though, if you want to print multiple digits — ie for a sum >= 10 — you'll need a real conversion from integer to ascii (and maybe vice versa too) so as to print as many digits as necessary.但是,一旦您处于处理字符的模式,如果您想打印多个数字 - 即总和 >= 10 - 您需要从 integer 到 ascii 的真正转换(反之亦然),以便根据需要打印尽可能多的数字。 (FYI, there's lots of examples of this in different languages, sometimes called itoa and atoi — for ascii to int and int to ascii respectively.) (仅供参考,在不同的语言中有很多这样的例子,有时称为itoaatoi - 分别用于 ascii 到 int 和 int 到 ascii。)


To test for !要测试! you'll need a subtraction of the ascii code for !您需要减去 ascii 代码! , namely 33, followed by a SkipCond 000/Jump Loop sequence that tests for zero and skips the backward branch on zero (equal to ! ). ,即 33,后跟一个SkipCond 000/Jump Loop序列,该序列测试零并在零处跳过反向分支(等于! )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM