Re: referring to segments other than DS - how?



Pop Tart wrote:
Hi,

I'm back again with two 16-bit newb questions :)

1)
With int 21h function 3Fh, I'm trying to write then read an array of bytes in the uninitialized data section.

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 (BSS) in MASM. I know how to set DS to "DATA" segment in MASM :

mov ax, @data
mov ds, ax

so for BSS, would it be:

mov ax, _BSS

I tried @BSS, that didn't assemble.
;-----------------------------------

I'm not sure about this one - I'd assume data and bss are in the same segment...

2)

Secondly, if I set ES to the data segment, DS, for example

mov ax, @data
mov es, ax

How do I de-reference a byte that is offset in the ES section? Which registers are legal to use?

ie, this isn't assembling for me:

mov ax, @data ; set es to data segmet
mov es, ax

mov dx, OFFSET InputBuffer
mov al, BYTE PTR es:[dx]

The MASM assembler complains about the last line, saying:
main.asm(134): error A2031: must be index or base register.

I change 'dx' to 'di' and it assembles ok. Which other registers are legal?

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
.



Relevant Pages

  • Re: Linux Sys Calls - int 80h
    ... load the parameters in the required registers and make the "int 0x80" ... Clearly, this stuff is all "processor specific"...also, UNIX doesn't ... are "processor specific" and UNIX was designed with "portability" in ...
    (alt.lang.asm)
  • Re: EOF
    ... Knowing about CPU registers is not necessary at all, ... fgetcreturns an int value which is either: ... The standard requires EOF to have a negative value. ... Since a valid unsigned char value can be any non-negative value in the ...
    (comp.lang.c)
  • Re: [PATCH] Add driver for Dallas DS1682 elapsed time recorder
    ... On 5/10/07, Jean Delvare wrote: ... > + * Low level chip access functions ... > + int val; ... you can check the number of registers? ...
    (Linux-Kernel)
  • [PATCH 2.6] I2C: New chip driver: sis5595
    ... +/* The SIS5595 registers */ ... +static inline u8 FAN_TO_REG(long rpm, int div) ... we save and restore the fan minimum here, ...
    (Linux-Kernel)
  • Re: [PATCH 2.6] I2C: New chip driver: sis5595
    ... 2.6.11-rc2-mm2 to add the sis5595 driver. ... +/* The SIS5595 registers */ ... +static inline u8 FAN_TO_REG(long rpm, int div) ...
    (Linux-Kernel)