r> Can you explain in some more detail about how ASSUME can be used
r> to catch errors?
Sure. Here's code (with a bug) which uses explicit overrides every time as
you've advocated:
-+--- bug1.asm begins
BIOS_DATA segment at 40h
serial dw 4 dup (?)
parallel dw 3 dup (?)
BIOS_DATA ends
DATA segment byte USE16 public 'CODE'
Count dw 0
DATA ends
CODE segment byte USE16 public 'CODE'
assume cs:CODE, ds:DATA
SerialCount proc near
push bx
push cx
push ds
mov ax,seg BIOS_DATA
mov ds,ax
mov cx,4
mov bx,offset serial
xor ax,ax
more:
cmp ax,ds:[bx]
adc ds:[Count],ax
inc bx
inc bx
loop more
mov ax,ds:[Count]
pop ds
pop cx
pop bx
ret
SerialCount endp
CODE ends
end
-+--- bug1.asm ends
The error, of course, is that ds is used to refer to Count even though ds points
to some other segment! The effect in this case is that the code can actually
alter the BIOS data area and return an incorrect result. Unfortunately, this
will assemble and link with no warnings and no errors.
Here's what happens if you use ASSUME correctly and omit the explicit segment
overrides:
-+--- bug2.asm begins
BIOS_DATA segment at 40h
serial dw 4 dup (?)
parallel dw 3 dup (?)
BIOS_DATA ends
DATA segment byte USE16 public 'CODE'
Count dw 0
DATA ends
CODE segment byte USE16 public 'CODE'
assume cs:CODE, ds:DATA
SerialCount proc near
push bx
push cx
push ds
mov ax,seg BIOS_DATA
mov ds,ax
assume ds:BIOS_DATA
mov cx,4
mov bx,offset serial
xor ax,ax
more:
cmp ax,[bx]
adc [Count],ax
inc bx
inc bx
loop more
mov ax,[Count]
pop ds
pop cx
pop bx
ret
SerialCount endp
CODE ends
end
-+--- bug2.asm ends
The assembler will (correctly) report that Count cannot be addressed via the
currently ASSUMEd segment registers and point to the lines which attempt to
address Count thereby catching bugs before they happen.