Search code examples
assemblyx86-16tasm

Assembly stores to DATA segment not all showing up


I got a question in my Computer Science Class to write in DATA SEGMENT from cell 0h to 100h and it's half working, it's overwrite every cell excluding EE to FF

Start:
    mov ax, @data
    mov ds, ax
    mov si, 100h ; starting DATASEG
    mov cx, 0h ; counting 
    mov al, 0FFh ; Number setting in each segment

loop1: 
    mov [si],al
    dec si ; decrease location
    inc cx ; increase counting
    CMP cx,101h
    jne loop1

Result:

enter image description here


Solution

  • I think @Michael has found the reason: SS = DS, and your SP=100h, so interrupt handlers will clobber the space below SP. This is the end of the to DS:00.. DS:100h range that is getting overwritten.

    Even the debugger itself may be partially intrusive and clobber memory below the debugged program's SP (e.g. when an int3 instruction pushes exception-return info). (You're running TurboDebugger inside DOSBOX, rather than using a debugger built-in to DOSBOX or BOCHS; that would let you debug fully non-intrusively, but timer interrupts would still clobber below SP when you don't have interrupts disabled).

    So your code worked, but its results were overwritten by the stack.