简体   繁体   English

LC-3如何打印两位数

[英]LC-3 How to print two digit number

I have an LC-3 program that has a counter. 我有一个带有计数器的LC-3程序。 I can print the counter to the screen using TRAP x21. 我可以使用TRAP x21将计数器打印到屏幕上。 However, if the counter number has two digits my program does not work. 但是,如果计数器编号为两位数,则我的程序无法正常工作。

Example: 9 will print perfectly, but not 19. 示例:9将完美打印,但19不完美。

I am guessing that before I print my Register which contains the counter I need a loop, which will chop the number by dividing by 2 (same as I would in decimal by dividing by 10, but 2 in binary). 我猜想在打印包含计数器的寄存器之前,我需要一个循环,该循环将除以2(与十进制除以10,而二进制以2表示)相同。 Then I guess I would print digit1, digit0. 然后我想我会打印digit1,digit0。 I have a problem though, how do I divide in LC-3? 我有一个问题,如何在LC-3中划分? Right shift? 右移? That seems too hard for this problem and beyond my knowledge. 对于这个问题,这似乎太困难了,超出了我的理解。

Please help. 请帮忙。

    0010 000 000000011    ; R0 <= x30 which is for  
    0001 000 000 0 00 010 ; R0 <= R0 + R2 

    1111 0000 00100001    ; TRAP x21 
    1111 0000 00100101    ; TRAP x25 
    0000000000110000

It only works with one digit because of your number->digit routine. 由于您的数字->数字例程,因此只能使用一位数字。 You're adding a number to the character '0', and obviously there's no character '11', etc. 您要在字符“ 0”上添加数字,并且显然没有字符“ 11”,依此类推。

You can find the maximal divisor by multiplying by ten (usually by repeated addition) until the divisor exceeds the number (then backing off to the previous value). 您可以找到最大除数,方法是乘以十(通常是通过重复加法),直到除数超过数字(然后退回到上一个值)。 This will let you use Gareth's method, above. 这将使您可以使用上面的Gareth方法。

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

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