-1
很新的程序集!给定的十六进制输入应该转换为十进制
我的汇编代码需要十六进制输入,它是0-9,而其他输入会导致错误,输入的每个字符都存储在一个数组中,并且数组中的每个元素都将被打印出它们的整数值,但出于某种原因,元素地址正在打印。 请参阅下面的代码,并给我解决我的问题。如果你需要完整的代码,请让我知道。
(以下代码的想法是采取的十六进制数的每个元素并打印在十进制数的元素)
mov ebx, array
next_loop: ;this loop is to convert the character
mov al, [ebx]
cmp al, NEWLINE ; here NEWLINE is 10 which is already defined
je end_loop
cmp al, 97
jge subblock
jl numsub
numsub:
sub al, 48
mov [ebx], al
jmp next
subblock:
sub al, 97
add al, 10
mov [ebx], al
jmp next
next:
inc ebx
loop next_loop
; below code is to print the value which is stored in array
end_loop:
mov ebx, array
mov eax, message2
call print_string
print_loop:
mov al, [ebx]
inc ebx
call print_int ; addresses of ebx is printing but not the value
cmp al, NEWLINE
jne print_loop
jmp finalend
请解决我的问题。 非常感谢。
很难说没有看到'print_int'的功能是怎么回事。你怎么知道它正在打印地址,而不是其他一些无效值?另外,由于您使用'NEWLINE'作为循环结束条件,您真的想要使用'loop'吗? 'ecx'是否具有您为循环计数器设置的值?如果不是,那么它只会循环发生在'ecx'中或直到'NEWLINE'的次数,以先到者为准。 – lurker
你也会有冲突:'10'是'NEWLINE',在你的最终答案中也是一个有效的十六进制数字值(你的打印代码无法区分'NEWLINE'和原来的'a十六进制数字)。 – lurker