What does stripping off the ASCII template mean?

浪尽此生 提交于 2019-12-02 07:03:25

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/30005154/what-does-stripping-off-the-ascii-template-mean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!