【发布时间】:2016-10-20 02:52:54
【问题描述】:
我正在尝试使用 x86 架构学习汇编。我可以进行基本计算,例如 add、sub、mul、imul、div 和 idiv。但是,当我尝试打印结果时,字符串中有几个空格。有没有办法删除这些额外的空间?我目前正在尝试通过遍历一个字符串并将非空格字符发送到第二个字符串来删除它们。如果这是这样做的方法,为什么我的代码不起作用?我在某处读过有关交换(xchg)的信息,但我不完全确定如何使用它。这会是一种更有效的方法吗?
dtoa product, eax ; convert to ASCII characters
dtoa xStart, x
dtoa yContinue, y
lea edi, product
mov ecx, 20h ; mov hex value of space into ecx
forStart: cmp [edi], ecx ; compare edi to space
jne addToString
add edi, 4 ; get address of next array element
cmp [edi], 00h ; cmp value of edi to null
je printResult
jmp forStart ; loop through for next element
addToString: mov ecx, [edi] ; mov value of edi into ecx
add edi, 4 ; get address of next array element
cmp [edi], 00h ; cmp value of edi to null
je printResult
jmp forStart ; loop through for next element
printResult: output resultLbl, xStart ; output result
【问题讨论】: