程序LC3汇编语言 [英] program for LC3 Assembly language

查看:3254
本文介绍了程序LC3汇编语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从用户的任何字符输入转换成其对应的十进制值?我只是遇到了麻烦开始了。

该方案已实现了以下几件事:


  1. 该程序从键盘字符接受


  2. 如果该字符是数字('0'到'9'):
    A)转换字符到其对应的十进制值。换言之,0变为零,'1'变为1,...9变成9.让我们称该值R(对于行程长度)。
    b)等到(使用GETC)其它字符。
    C)打印该字符到控制台中的R副本。 )
    D)回到步骤1。


  3. 另外,如果字符是输入/返回(ASCII#10):打印一个换行符(ASCII#10)到控制台,并返回到第1步


  4. 另外,如果字符是什么都重要,停止程序。



解决方案

您转换十进制数字字符它减去它'0'(=的0x30)的数量。
对于十六进制数字('A'to'F'):
如果字符是大于'@',你减去它0x37符号('A' - >的0x0A)。
对于十六进制数字('a'to'F'):
如果该值仍大于15大,则减去它0x20的
或者你可以使用一个表映射。 256字节是不是BERY大表。


  • 您设定的结果(变量,寄存器,...),以零

  • 您读取每个字符都在一个循环

  • 您的字符转换为新号码(个位数)的

  • 如果它是无效的十六进制数字字符,返回变量 - 大功告成

  • 其他变量=变量* 16 +新号码

  • 16乘以可以通过左移4位的地方
  • 完成

How do you convert any character input from the user to its corresponding decimal value? I was just having trouble getting started.

The program has to achieve the following things:

  1. The program accepts character from keyboard.

  2. If the character is a digit (‘0’ through ‘9’): a) Convert the character to its corresponding decimal value. In other words, ‘0’ becomes zero, ‘1’ becomes 1, ... ‘9’ becomes 9. Let’s call that value R (for "run length"). b) Wait for another character (using GETC). c) Print R copies of that character to the console. ) d) Go back to Step 1.

  3. Else, if the character is Enter/Return (ASCII #10): Print a linefeed (ASCII #10) to the console, and go back to Step 1.

  4. Else, if the character is anything else, halt the program.

解决方案

You convert decimal digit character it to number subtracting '0' (=0x30) from it. For hex digits ('A'to 'F'): If character is greater than '@', you subtract 0x37 from it ('A' -> 0x0a). For hex digits ('a'to 'f'): If the value is still bigger than 15, you subtract 0x20 from it Or you can use a table for mapping. 256 bytes is not bery big table.

  • You set result (variable, register, ...) to zero
  • You read character by character in a loop
  • You convert the character to new number (of one digit)
  • if it's invalid hex digit character, return the variable - you're done
  • else variable = variable * 16 + new number
  • multiplying by 16 can be done by shifting left 4 bit places

这篇关于程序LC3汇编语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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