将4位十六进制转换为其对应的7位ascii-code,汇编代码

时间:2013-01-22 17:27:32

标签: assembly if-statement conditional-statements flowchart nios

我的任务是创建一个子程序,将4位十六进制值转换为相应的7位ASCII码。例如。 0010为2转换为011 0010(ASCII为'2'),1011为B转换为100 0010(ASCII为'B')。

编辑,这应该是答案

.global hexasc              # makes hexasc globally known

hexasc:   andi  r2, r4,0xF  # Masks away the four MSB, r4 = input value
        movi  r10, 10       # Constant, compare value in cond

cond:   bge   r2, r10, yes  # if r4 is >= 10 then branch yes, else no
                            # yes = letter, no = numbers

no:     addi  r2, r2, 0x30  # Adds 0x30I've been learning assembly code for about a week so please keep in mind that my knowledge is very limited. And yes, I've been did do some google search before ending up here! (0011 0000) to convert into the 7bit ASCII value
        br    end           # Branch to the end, r2 is the return value

yes:    addi  r2, r2, 0x37  # Adds 0x37 (decimal: 55) to increase the ASCII value
                            # B (number) = 11 (decimal) --add55-> 66 (decimal) = B (char)

end:    ret                 # Sub-routine ends, return r2

0 个答案:

没有答案