0

I am trying to fill an empty string rev with the reverse of abc string but it gives error at line 20. that is wrong parameter or probably it is an undefined var.

.model small
.data
abc db "i eat an apple a day$"
rev db ?

.code
main proc
    mov ax,@data
    mov ds,ax
    ;mov cx,size
    mov bx,offset abc
    ;add bx,size
    dec bx
    ;add bx,cx
    mov dx,offset abc 

copy:
    mov al,byte ptr[bx]
    ;Error over here:(20) wrong parameters: MOV  byte ptr[dx],al
    ;(20) probably it's an undefined var: byte ptr[dx] 
    mov byte ptr[dx],al
    dec bx
    inc dx
    loop copy
    mov byte ptr[dx],'$'
    mov dx,offset rev
    mov ah,9
    int 21h
    mov ah,4ch
    int 21h
    main endp
end main

I am trying to fill an empty string rev with the reverse of abc string but it gives error at line 20 .that is wrong parameter or probably it is an undefined var.

HamidReza
  • 717
  • 7
  • 17
  • 3
    Only some registers can be used as addresses in 16-bit assembly. See e.g. http://stackoverflow.com/questions/32351554/the-instruction-mov-ax-ax-wont-compile – Michael Feb 06 '17 at 07:22
  • Also this answer is relevant for you, as you are in the same misconception of `rev db ?` being *"an empty string"*, while it is just single undefined byte (1 ASCII character at most): http://stackoverflow.com/a/40580889/4271923 – Ped7g Feb 06 '17 at 11:38

1 Answers1

0

You can use SI and DI registers with arrays instead of BX and DX. That is exactly what they are for. Registers in 8086

Here is a working modified version of your code :

.model small
.data   

abc db "i eat an apple a day$"
lenAbc db $-abc      ; size of abc array
rev db 0

.code
main proc

    mov ax,@data
    mov ds,ax      

    mov di, 0              

    dec lenAbc
    mov cx, word ptr lenAbc   ; size of array ( excluding '$' ) 

    dec lenAbc
    mov si, word ptr lenAbc   ; index of last element in an array into SI

copy:

    mov al, abc [si]
    mov rev [di],al     ; populate rev with abc starting from last element
    dec si
    inc di
    loop copy

    mov rev [di],'$'

    mov dx,offset rev
    mov ah,9
    int 21h

    mov ah,4ch
    int 21h

main endp

end main

Tested in emu8086

Ahtisham
  • 9,170
  • 4
  • 43
  • 57