Curiosity about data segment initialization

Started by falcon01, July 31, 2011, 10:49:28 AM

Previous topic - Next topic

falcon01

Sorry, where someData would be?In another data segment?
I tried

lea dx,FIRSTR

instead of using offset directive and it works fine...

dedndave

sorry - i should have given a clearer example....
notice that, in our keyboard entry program, we do not access and data via labels directly
we load the offset into a register and address the data via register

for most programs you write, however, you will access data directly via the label...
        .DATA

SomeData dw 5

        .CODE

        mov     ax,SomeData
        add     ax,3
        mov     SomeData,ax

for this type of access, the ASSUME directive will be required

for this type of access, it is not....
        .DATA

SomeData dw 5

        .CODE

        mov     bx,offset SomeData
        mov     ax,[bx]
        add     ax,3
        mov     [bx],ax

falcon01

Sorry again, I'm the newby here but your "assume is needed part" still works without assume...
here's my code
;----------------------------------------------------------------------------------------
SSEG SEGMENT PARA STACK 'STACK'
db 128 dup(?)
SSEG ENDS 

;-----------------------------------------------------------------------------------------
DSEG segment para public 'DATA'

SomeData dw 5


DSEG ENDS

;-----------------------------------------------------------------------------------

CSEG SEGMENT PARA PUBLIC 'CODE'

;----------------------------------------------------------------------------------------------------------------------
; Main proc
;----------------------------------------------------------------------------------------------------------------------
MAIN proc far
mov    ax,DSEG
mov    ds,ax
    ; Program
mov     ax,SomeData
     add     ax,3
     mov     SomeData,ax

mov ah,4ch   
int 21h
; Exit program, return to OS
MAIN endp 

CSEG ends     
;---------------------------------------------------------------------------------------
        ;ASSUME CS:CSEG,SS:SSEG,DS:DSEG <---commented
end MAIN


Maybe it's because I'm using 8086emu for 16bit programming?

dedndave

yah - most of us use MASM
some use JwAsm, GoAsm, a few others
our statements about ASSUME apply primarily to MASM

ASSUME at the end of the source file does nothing, really   :P
MASM treats ASSUME in a serial manner, with regard to other text in the source
        ASSUME  DS:DSEG1

;the assembler assumes DS is pointing to DSEG1 for any source text here

        ASSUME  DS:DSEG2

;the assembler assumes DS is pointing to DSEG2 for any source text here

        ASSUME  DS:DSEG1

;the assembler assumes DS is pointing to DSEG1 for any source text here

        ASSUME  DS:Nothing

;the assembler assumes nothing about DS for any source text here


ASSUME may also be used in other ways
for example, it may be used to tell the assembler that EBX is pointing to a particular data type or structure
        ASSUME  EBX:Ptr BYTE

        mov     [ebx],0             ;stores a byte at [EBX]

        ASSUME  EBX:Ptr DWORD

        mov     [ebx],0             ;stores a dword at [EBX]


the default assumption about EBX is Nothing
so, without the ASSUME's, you would have to...
        mov byte ptr [ebx],0        ;stores a byte at [EBX]
        mov dword ptr [ebx],0       ;stores a dword at [EBX]