【问题标题】:LC-3 binary instructions exerciseLC-3 二进制指令练习
【发布时间】:2015-07-05 18:34:42
【问题描述】:

这是我现在拥有的 LC3 模拟器的代码:

0011000000000000 0101010010100000 0010011000010000 1111000000100011 0110001011000000 0001100001111100 0000010000001000 1001001001111111 0001001001100001 0001001001000000 0000101000000001 0001010010100001 0001011011100001 0110001011000000 0000111111110110 0010000000000100 0001000000000010 1111000000100001 1111000000100101 0011000100000000 0000000000110000

这是一个程序,它识别整个字符串中的单个字符,然后输出找到该字符的次数..

我有 2 个问题..

1) 代码的工作原理是输出我在字符串中找到某个字母的次数...但我需要对其进行修改,以便它在找到该字符的地址的内存中建立一个列表.. 我需要让这个列表从内存位置 x3200 开始

2) 只有在 0-9 次之间找到该字符时,该代码才有效。我需要对其进行修改,使其在 0-99 次之间有效

我不是在要求答案...我只是感谢有关如何解决此问题的任何指示...谢谢

【问题讨论】:

  • 有什么方法可以在 asm 中发布代码吗?这将使帮助回答您的一些问题变得更加容易。
  • 对不起,我还没有学会那个符号,所以我不知道怎么用 asm 写它

标签: binary simulator lc3


【解决方案1】:

好吧,我想我开始对这个问题有了更多的了解。我创建了一个二进制文件,然后将其加载到 LC3 的模拟器中以生成一些可读的 asm。这是我得到的:

Memory:
 x3000  0101010010100000  x54A0  AND    R2, R2, #0     // Clear R2
 x3001  0010011000010000  x2610  LD     R3, x3012      // load the the value stored at x3012 into R3
 x3002  1111000000100011  xF023  TRAP   IN             // input char
 x3003  0110001011000000  x62C0  LDR    R1, R3, #0     // load the value of memory R3 into R1
 x3004  0001100001111100  x187C  ADD    R4, R1, #-4    // Add -4 to R1 to see if we have reached the end of our string
 x3005  0000010000001000  x0408  BRZ    x300E          // Output result, end program if we run into an x0004 in the string
 x3006  1001001001111111  x927F  NOT    R1, R1         // invert the char from the 
 x3007  0001001001100001  x1261  ADD    R1, R1, #1     // stored string
 x3008  0001001001000000  x1240  ADD    R1, R1, R0     // compare with the char entered by the user
 x3009  0000101000000001  x0A01  BRNP   x300B          // If the chars don't match grab another char from the string
 x300A  0001010010100001  x14A1  ADD    R2, R2, #1     // R2 is our char counter, counts the number of times we find
                                                       // the user's char in the string
 x300B  0001011011100001  x16E1  ADD    R3, R3, #1     // increment our memory pointer
 x300C  0110001011000000  x62C0  LDR    R1, R3, #0     // load the value of memory R3 into R1
 x300D  0000111111110110  x0FF6  BRNZP  x3004          // Jump to      x3004
 x300E  0010000000000100  x2004  LD     R0, x3013      // Load the value of      x30 into R0
 x300F  0001000000000010  x1002  ADD    R0, R0, R2     // Add      x30 to our count to convert it to ASCII
 x3010  1111000000100001  xF021  TRAP   OUT            // Output the count to the user
 x3011  1111000000100101  xF025  TRAP   HALT           // Stop the program
 x3012  0011000100000000  x3100  ST     R0, x2F13      
 x3013  0000000000110000  x0030  NOP

为了帮助您开始回答第一个问题,我会做一些类似于如何使用 R3 的事情。将内存位置 x3200 加载到未使用的寄存器中,然后每次在该内存位置存储地址时递增它。示例:

LD R5, x3013      // store x3200 in the memory location x3013
.
.                 // if the chars match then do the following
.
STR R3, R5, #0    // Store the value of R3 into the mem of R5
ADD R5, R5, #1    // increment R5

至于您的第二个问题,它仅输出值 0-9 的原因是因为您通过添加 x30 将计数值转换为 ASCII 字符。这对于前 10 个整数非常有用,但您必须有一点创意才能添加第二个数字。

希望这会有所帮助。

【讨论】:

  • 不知道是不是太复杂了,还是有其他更简单的方法?另外,很抱歉它的格式化方式。我试图把它变成段落,但它不会让我
  • 很高兴我能帮上忙。由于您使用的是单个 ASCII 字符,因此我可能会这样做。我不确定是否有更简单的方法。请记住我的解决方案是否有助于将其标记为已回答。
  • 好的,再次感谢您的帮助!我将其标记为已回答
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-25
  • 2018-04-05
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
相关资源
最近更新 更多