我试图将字符串转换为整数,然后再转换回字符串。但它给出了一些奇怪的值,我已经更新了尝试其他东西,请再次检查代码。为什么输出不正确?
稍有更新,但输入仍不正确
.model small
.stack 100h
.data
input db 30 dup ('$')
n dw ?
count db ?
output db 30 dup ('$')
.code
main proc
mov ax , @data
mov ds , ax
mov bx , offset input
mov count , 0
; mov ax,0
l1:
mov ah , 1
int 21h
mov [bx] , al
inc bx
inc count
cmp al , 13
jne l1
mov ax , 0
mov bx , offset input
l2 :
dec bx
mov dx , [bx]
add dx , 48
mov cx , 10
mul cx
add ax , [bx]
dec count
cmp count , 0
jne l2
mov ax , bp
mov bx , offset output
l3 : ; loop
mov dx, 0 ; dx = 0
mov cx,10 ; cx is a loop variable
div cx
add dl,48 ; adding 48 for ascii character
mov [bx], dl ; adding the value of each number in array
inc bx ; decrement pointer
cmp ax, 0 ; comparing ax
jne l3 ; jump not equal to
mov dx , offset output
mov ah, 9
int 21h
mov ax, 4c00h
int 21h
main endp
end main
1条答案
按热度按时间sirbozc51#
修复!这里是(与大量的评论):