Re: referring to segments other than DS - how?



On Wed, 27 Feb 2008 17:48:51 +0000, Frank Kotler wrote:

Using 16-bit instructions, si and di are "index" registers, bx and bp
are "base" registers. You can use an (optional) offset, plus an
(optional) base register, plus an (optional) index register. That is,
[si + bx] is okay but [si + di] is not. We can, even in 16-bit code, use
32-bit addressing modes - mov al, BYTE PTR es:[edx] would work. I think
you'd need to "enable" 32-bit instructions for Masm - ".386" *after* the
".model" directive, IIRC. Simplest thing is to stick with si, di, and bx
for addressing (bp is "special" in that it defaults to ss:[bp]).

Best,
Frank

Thanks Frank. Maybe you or someone else can help with this. Assuming I
only have 16-bit registers, and I've got a buffer in BSS, how do I write
the buffer to a file? If I understand correctly, function 40h / int 21h
needs the address of the buffer to be in DS:DX, so I have to move the BSS
segment to DS. However, my program is terminating on the int 21h below -
before even setting error code to AX or setting the Carry Flag.

(I have ES set to BSS below. label 'InputBuffer is an offset into BSS)

mov ax, 40h ; func. write array
mov bx, EncFileHandle ; file handle to bx
mov cx, 500 ; bytes to write from 3fh abv

mov di, es
mov ds, di ; set ds to es for inp.buffer

mov dx,OFFSET InputBuffer
int 21h ;terminates abrubtly here

cmp ax,0 ; did we write anything
je EmptyOutput

Only thing I can think is that EncFileHandle, which is a label to an
offset into the regular Data Segment (not BSS), causes it to screw up...
However, reading a file into this array in the same fashion, with 3Fh /
int 21h, didn't have a problem. If the function *is* interpreting
EncFileHandle to be in *BSS*, how the heck does anyone write to an
uninitialized buffer? !@#$%! :)

Again, I'm trying not to use 32-bit registers. Many thanks in advance.





--
Regards,
Pop Tart
.



Relevant Pages

  • Re: referring to segments other than DS - how?
    ... only have 16-bit registers, and I've got a buffer in BSS, how do I write ... BSS segment to DS. ... OpenEncFile PROC ...
    (alt.lang.asm)
  • Re: referring to segments other than DS - how?
    ... only have 16-bit registers, and I've got a buffer in BSS, how do I write ... needs the address of the buffer to be in DS:DX, so I have to move the BSS ... EncFileHandle; file handle to bx ... I'm trying not to use 32-bit registers. ...
    (alt.lang.asm)
  • Re: referring to segments other than DS - how?
    ... When I call the int 21h / 3Fh to read from a file and store in an uninitialized buffer - I assume the interrupt wants both BX and DX to be offsets to DS, so how do I set DS to uninitialized section in MASM. ... I tried @BSS, that didn't assemble. ... Which registers are legal to use? ... You can use an offset, plus an base register, plus an index register. ...
    (alt.lang.asm)
  • Re: Massbus configuration issues and restrictions
    ... > (niether the mainline driver nor the boot driver) doesn't use them. ... The register count jumper sets the offset ... and the DCL registers live in the hole. ... with the MBA2 set always at the same offset. ...
    (comp.os.vms)
  • Re: The future of CPU based computing, mini clusters.
    ... even giving a plentiful set of offset ... and those registers were recycled for ... That's more or less how the 286 MMU worked, and versions of QNX ... The early ARM systems had a funky memory protection-but-no-mapping system ...
    (comp.arch)