x86参数有非法大小[tasm]

时间:2015-01-11 18:15:03

标签: assembly tasm

我有一项任务是通过以下规则更改一串数字(<=100):nr becomes 1 if it's less tham 60 and 2 if not。我出来了这段代码。我认为最大的挑战是打印数字......但是它给了我2个错误,指出代码标记为:

Prints macro number
    mov bx, 10      ; need to divide by 10 to get the last digit
    mov al, number
    mov ah,0
    mov cx,0
    decompose:      
        inc cx
        div bx          ; reminder stored in ah
        mov dl,ah
        add dl,48       ; to convert to char ; <<<<< HERE
        push dl
        cmp al,0        ;the nr=0 means that the loop ends
        jnz decompose

    printloop:  ;loops for as many times as counted in cx ; <<<< HERE
        pop dl  
        mov ah,2h       ; prints whatever is in dl
        int 21h
    loop printloop

        mov dl,' '      ; the space after a number
        mov ah,2h
        int 21h

endm

data segment para public 'data'
    sir DB 15, 78, 12, 39, 42, 88
    lungime_sir EQU $-sir
data ends

;stack segment para public 'stack'
;   dw stack_size dup(?)
;   stack_start label word
;stack ends

code segment para public 'code'
start proc far
    assume cs:code, ds:data
    push ds
    xor ax,ax
    push ax
    mov ax, data
    mov ds, ax

    mov si,0
    mov cx,lungime_sir

next: 
    cmp sir[si],60
    jb mic
    mov sir[si],2
    inc si
loop next

mic: 
    mov sir[si],1
    inc si
    cmp si,lungime_sir
    jle next


    mov cx,lungime_sir
    mov si,0

    ;put values on a stack and pop them out 
print:
    Prints sir[si]
    inc si

loop print


        ret
start endp
code ends
end start

怎么了? :(

1 个答案:

答案 0 :(得分:0)

push dlpop dl更改为push dxpop dx。你不能推/弹一个字节。

div bx          ; reminder stored in ah

将此除法更改为div bl以获得AH中的余数。

mov ah,0放在标签分解之后,以获得成功的第二次和第三次迭代

mov cx,0
decompose: 
mov ah,0

您已将 Prints 定义为不保留任何寄存器的宏。因此,以下代码将无法按预期工作。至少推/弹CX。

print:
 Prints sir[si]
 inc si
loop print