Search code examples
assemblytasm

x86 Argument has Illegal Size [tasm]


I have this task to change a string of numbers(<=100) by the following rule: nr becomes 1 if it's less tham 60 and 2 if not. I came out with this code. I thought the biggest challenge was to print the numbers... but it gives me 2 errors pointed as marked on the code:

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

What's wrong? :(


Solution

  • Change push dl and pop dl into push dx and pop dx. You cannot push/pop a byte.

    div bx          ; reminder stored in ah
    

    Change this divide into div bl to obtain the remainder in AH.

    Put mov ah,0 after the label decompose to get successful second and third iterations

    mov cx,0
    decompose: 
    mov ah,0
    

    You've defined Prints as a macro that doesn't preserve any registers. So the following code will not work as expected. At least push/pop CX.

    print:
     Prints sir[si]
     inc si
    loop print