Take the 2-minute tour ×

I'm trying to learn assembly language but I have a simple problem with writing to an array. My program should read command line arguments, display them and write to an array. In code below there is one marked line. If i compile it with this line commented program works fine but if I uncomment it, it hangs after displaying few chars. Whats wrong here? It works when there is shorter arguments line but this array should be big enough to contain whole command line. Am I missing something here?

                                 assume cs:kod, ds:dane 

kod     segment


mov     ax,seg wstos
mov     ss,ax
mov     sp,offset wstos                               

xor     cx,cx
xor     ax,ax    
mov     si,80h 
mov     dl,[si]
mov     cl,dl
mov     ah,2h
int     21h
inc     si
xor     di,di

    inc     si
    mov     dl,[si]
    ;mov        [tablica + di],dl  <<<< this line
    test    dl,dl
    jz      sprawdz
    int     21h
    inc     di
loop    petla

    mov     al,[si+1]
    cmp     al,0
    jne     dalej

mov     ax,4c00h  
int     21h

dane    segment
    tablica     db  128 dup(0)
dane    ends

stos1   segment STACK
    dw  256 dup(?)
    wstos   dw  ?
stos1   ends
share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

I think that offset tablica == 0, but also ds==cs. At least it has to be, if these lines work as expected:

mov si, 80h
mov al, [si]; 

To make it compliant, either ds has to be initialized (in which case the command line is accessed with mov al,cs:[si], or you can simply leave the data to the code segment by commenting 2 lines out:

;dane    segment
    tablica     db  128 dup(0)
;dane    ends
share|improve this answer
Thanks for help. I have actually solved it myself yesterday. ;) Problem was not initializing ds register. Now everything works ok. Always thought that assume command does it for me. So what actually this command is doing? Can't find it anywhere. –  Dcortez Jan 3 '13 at 10:39
When assembler tries to calculate the addresses/offsets of label (in ds:segment) it does it in reference to the parameter in the assume directive. This of course presupposes, that ds contains the value of the assumed segment. Another use is in invoke/call macros, where a pointer (eg. di) can be assumed to point to byte, word, dword or even a struct. –  Aki Suihkonen Jan 3 '13 at 11:03
add comment

"mov [tablica + di]" What about ES?

share|improve this answer
Yeah... and what about ds? You initialize stack at the start: label (which probably isn't necessary) but don't initialize ds or es. The assume directive does NOT do this for you. On startup, DOS will initialize ds and es to your PSP segment - which is where your command line arguments are - but your tablica is in segment dane. I think you're going to need a segment override in one case or the other. –  Frank Kotler Jan 2 '13 at 15:48
No way; he has multiple segments, hence, it is an EXE program. –  Aleksey Ivchenko Jan 2 '13 at 18:18
add comment

Your Answer


