【问题标题】:MARIE calculator not working as intendedMARIE 计算器未按预期工作
【发布时间】:2018-06-09 23:23:12
【问题描述】:

我需要在 MARIE 中为一个计算器编写代码,该计算器需要 2 个数字 x 和 y,打印 > x + y = z。计算器不打算计算两位数的答案。我遇到的问题是一切正常,除了结果将是一个随机的 ASCII 字符而不是想要的结果。

例如,5 + 4 = i 和 3 + 2 = e

ORG 100
load a
output / prints ">"
input
store x / takes input and stores into x
load x
output / loads x into AC and output
input
store y / takes input and stores into y
load b
output / prints "+"
load y
output / prints y
load c
output / prints "="
load x
add y
store z / adds x and y, stores into z
load z
output / prints z (the result)
halt

a, hex 3E
b, hex 2B
c, hex 3D
x, hex 0
y, hex 0
z, hex 0

【问题讨论】:

  • 您正在添加 ascii 代码。因此5+4 变为0x35+0x34=0x69,实际上是i
  • 哦!我想我明白了。所以我只需要用 30 代替这些值,应该没问题吧?

标签: assembly marie


【解决方案1】:

回答:

我发现结果中减去 48(十进制)将匹配代表所述数字的相应 ASCII 码的答案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-20
    • 2015-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-20
    • 2016-08-13
    相关资源
    最近更新 更多