2

我正在为装配制作 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 ?,?, '$'
4

1 回答 1

3

问题是您在从atoi. ret使用堆栈顶部的数据作为返回地址。可能的解决方案:不要将 eax 推入堆栈,只需从 eax 中返回atoi答案。因此,您不需要pop eax在代码的主要部分。

除此之外,您还需要确保它DS指向您的stri内存位置所在的代码段。对于程序的常规退出,请使用 int 21 function 4Ch。在 MS DOS 2.0 之后,不推荐使用 int 20。

于 2013-10-28T19:37:55.650 回答