什么是剥离的ASCII模板是什么意思? [英] What does stripping off the ASCII template mean?

查看:349
本文介绍了什么是剥离的ASCII模板是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在练习考试题

问题
 在此程序的执行中,用户输入两个数字。什么是xGuess的价值,所以我们可以脱光ASCII模板?解释。

  .orig这样X3000
TRAP X23
LD R2,ASCII
ADD R1,R2,R0
TRAP X23
ADD R0,R0,R2
ADD R0,R0,R1
.fill伪ASCII xGuess
。结束

使用 LC3大会中作为参考,我能够制定这一计划做什么(从上到下)


        
  1. 开始先放置code。在内存地址X3000

  2.     
  3. 允许用户输入一个字符,调用这个角色。注册0将存储k的值

  4.     
  5. xGuess - > R2

  6.     
  7. (K + xGuess) - > R1

  8.     
  9. 允许用户输入一个字符,称此字符c。 C-> R0

  10.     
  11. (C + xGuess) - > R0

  12.     
  13. ((C + xGuess)+(K + xGuess)) - > R0

所以,最后,R0将存储k值+ C + 2 * xGuess。
这里是我的LC3相同的运行(如下图所示)(xGuess = 4,K = 97,C = 98)

这证实了我的怀疑,因为R0是存储97 + 98 + 2 * 4或203。

有谁知道这个问题是指剥离的ASCII模板是什么?我不太明白的措辞,因为ASCII值会影响到什么样的价值获取存储在R0到底。

解决方案

当你注意到了,操作上输入字符的ASCII值执行。在装配中,如果你读的键盘字符,你真的得到他们的ASCII值在寄存器中,让我们说你进入2和3要添加他们,那么你真的加入 50 + 51 。你必须减去48首先,从每个输入的字符,因为48是ASCII字符0的值。我想,这就是所谓的剥离的ASCII模板。然后,如果你想在屏幕上显示计算的结果,你必须添加48回的结果(仅当输入的字符,结果是个位数,更大的数字它涉及更多的操作)。 Howerer,这将产生0-9感。我不知道为什么会你想在字母字符计算,像A和B​​在你的例子。

I am working on a practice exam problem

The Problem On execution of this program, the user inputs two numbers. What is the value of xGuess so we can strip off the ASCII template? Explain.

.ORIG x3000
TRAP x23
LD R2, ASCII
ADD R1, R2, R0
TRAP x23
ADD R0, R0, R2
ADD R0, R0, R1
ASCII .FILL xGuess
.END

Using Lc3 Assembly as a reference, I was able to work out what this program does(from top to bottom)

  1. Start placing code at memory address x3000
  2. Lets user input a character, call this character. Register 0 will store the value of k
  3. xGuess -> R2
  4. (k + xGuess) -> R1.
  5. Lets user input another character, call this character c. c->R0
  6. (c + xGuess) -> R0
  7. ((c + xGuess) + (k + xGuess))- > R0

So in the end, R0 will store the value of k + c + 2 * xGuess. Here is my same run(shown below) in Lc3 (xGuess = 4, k = 97, c = 98)

This confirmed my suspicions because R0 is storing 97 + 98 + 2 * 4 or 203.

Does anyone know what the question means by "stripping off the ASCII template"? I don't quite understand the wording because the value of ASCII will affect what value gets stored in R0 in the end.

解决方案

As you noticed, operations are performed on ASCII values of entered characters. In assembly, if you read characters from keyboard, you really get their ASCII values in registers, so let's say you enter 2 and 3 and want to add them, then you are really adding 50+51. You have to subtract 48 first, from each entered character, because 48 is a value of 0 character in ASCII. I think this is called "stripping off the ASCII template". Then, if you want to display the result of calculation on the screen, you have to add 48 back to the result (only if entered character and the result is single digit, for bigger numbers it involves more operations). Howerer, this makes sense for characters 0-9. I don't know why would you want to make calculations on alphabet characters, like a and b in your example.

这篇关于什么是剥离的ASCII模板是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆