2

I would like to get some help with this questions: what is correct and legal in following definition of the data segment:

data segment 
     x db -23, 3 or 4, not -3, 9 xor 15, 129, $+x, SEG x, -128 LT 80h 
     db -129, x+1, b2h, 256, 7852h, byte ptr z 
     y dw z-2, -7852h, x[2], offset bx 
     z dd z-y, FAR PTR y 
data ends 

I consider following wrong:

- cant contain operations:  3 or 4, not -3, 9 xor 15,  FAR PTR y, offset bx ...
- cant reference same varaible : $+x

And correct:

- -23, 129, 7852h ...
- a db 'abc'
  lengthOfa EQU ($-s) 

Am i right about this facts?

4

1 回答 1

2

Why don't you let the assembler answer? x, y, z are only labels, not variables. So you can separate the values and write them in several lines. Consider to keep the declarations (db, dw, dd). Build an assembly source text, let it assemble and look which line contains which error:

data segment
     x db -23
     db 3 or 4
     db not -3
     db 9 xor 15
     db 129
     db $+x         ; TASM: Can't add relative quantities - MASM: error A2101: cannot add two relocatable labels
     db SEG x       ; TASM: Not expecting group or segment quantity - MASM: error A2071: initializer magnitude too large for specified size
     db -128 LT 80h

     db -129
     db x+1         ; TASM: Expecting scalar type - MASM: error A2071: initializer magnitude too large for specified size
     db b2h         ; TASM: Undefined symbol: B2H - MASM: error A2006: undefined symbol : b2h
     db 256         ; TASM: Value out of range - MASM: error A2071: initializer magnitude too large for specified size
     db 7852h       ; TASM: Value out of range - MASM: error A2071: initializer magnitude too large for specified size
     db byte ptr z  ; TASM: Expecting scalar type - MASM: error A2071: initializer magnitude too large for specified size
     y dw z-2
     dw -7852h
     dw x[2]
     dw offset bx   ; TASM: Illegal use of register - MASM: error A2032: invalid use of register
     z dd z-y
     dd FAR PTR y
data ends

code segment
start:
    ret
code ends

end start
于 2015-01-28T20:24:02.353 回答