我正在制作atoi函数用于组装。
不管我怎么尝试,它都不起作用,我也不知道为什么。
有人知道问题出在哪里吗?
org 100h
mov si, stri ;parameter
call atoi ;call function
pop eax ;result
mov [broj], eax ;save
mov ah, 9 ;display (in ascii, because I don't have itoa function yet either)
mov dx, broj
int 21h
mov ah, 8
int 21h
int 20h
atoi:
mov eax, 0 ;stores result
mov ebx, 0 ;stores character
atoi_start:
mov bl, [si] ;get character
cmp bl, '$' ;till dollar sign
je end_atoi
imul eax, 10 ;multiplu by 10
sub bl, 30h ;ascii to int
add eax, ebx ;and add the new digit
inc si ;;next char
jmp atoi_start
end_atoi:
push eax ;return value
ret
stri db '1000$'
broj: db ?,?, '$'发布于 2013-10-29 03:37:56
问题是您在从atoi返回之前将eax推送到堆栈。ret使用堆栈顶部的数据作为返回地址。可能的解决方案:不要将eax推送到堆栈,只需从atoi返回eax中的答案。因此,您不需要在代码的主要部分使用pop eax。
除此之外,您还需要确保DS指向您的stri内存位置所在的代码段。要从程序中常规退出,请使用int 21函数4Ch。在MS DOS 2.0之后,不推荐使用int 20。
https://stackoverflow.com/questions/19643371
复制相似问题