Assembly lc3汇编-将ASCII转换为数字

Assembly lc3汇编-将ASCII转换为数字,assembly,lc3,Assembly,Lc3,我在R0中有一个ASCII字符,为了返回R0中的等效数字,我收到了以下指令: Find the index of the given ASCII_digit in “0123456789ABCDEF” The index is the Numeric_Digit equivalent of the given ASCII_Digit 这似乎是小菜一碟,但逐字检查的过程如下: DIGITS .STRINGZ "0123456789ABCDEF" ;Digit_String 这完全让我困惑 你

我在R0中有一个ASCII字符,为了返回R0中的等效数字,我收到了以下指令:

Find the index of the given ASCII_digit in “0123456789ABCDEF”
The index is the Numeric_Digit equivalent of the given ASCII_Digit
这似乎是小菜一碟,但逐字检查的过程如下:

DIGITS  .STRINGZ "0123456789ABCDEF" ;Digit_String
这完全让我困惑

你将如何做到这一点

我想您会将当前索引处的字符串的倒数添加到R0中的ASCII,如果它返回0,您会找到您的字符吗

请告知


谢谢你

你可以这样做:

LEA R1, DIGITS ;R1 is our string pointer/counter
START
    LD R2, R1 ;get the current character
    ADD R1, R1, 1 
    NOT R2, R2 ;these lines
    ADD R2, R2, 1 ;get the two's complement of R2, equivalent to -R2
    ADD R3, R0, R2 ;this is like cmp r0, r2
    BRnz ;loop back unless the characters are equal
LEA R2, DIGITS
NOT R2, R2 ;R2 = 1 - R2, we account for the 0
ADD R1, R1, R2
在此之后,R0中字符的整数值在R1中。R0未被触及


我假设LC3使用2的补码表示。

循环遍历字符串并返回索引,在?@s.Klumpers找到相应的值是的,这是合乎逻辑的做法。在LC3上实现它是我所困惑的。谢谢你的回答你有密码吗?到目前为止你累了什么?非常感谢你的回答。我一定会很快尝试的。当你说LC3是一种专门为教育目的而设计的语言时,我感到困惑。它实际上是一台机器,我可以用汇编语言和机器语言为它编程。我错过什么了吗?谢谢,这就解释了为什么文档这么少,删除了最后一段。