News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

DS override

Started by djshusko, November 23, 2008, 02:15:36 AM

Previous topic - Next topic

djshusko

I'm new to assembly and could use some help.  I'm writing a function that uses [bp+x] as a pointer to a variable.  Is there a more efficient way to retrieve the value of the variable than what I've been doing.  I've been using the following:

mov di,[bp+x]
mov al,[di]

I thought I could use a ds override, but I'm thinking the fact that its a pointer is prohibiting it.  If there's a way to retrieve this in one execution I'd love the help.  Thanks.

KeepingRealBusy

djshusko,

There is no other way. If [bp+x] is a pointer, you must first put the pointer in a register, then use that register to access the value.

Dave.

KeepingRealBusy

djshusko,

If you are going to be doing only 16 bit programming, then you might want to go to the 16 bit DOS forum at this site, most of the other forums are discussing 32 bit programming.

Dave.

MichaelW

#3
djshusko,

A segment override prefix overrides the default segment selection. It effectively specifies the segment the instruction is to use. It does not change the basic addressing mechanism.

I'm guessing here, but assuming that you are accessing the variable from a procedure where the variable was passed to the procedure by reference, the only way I know of to simplify the access is to pass the variable by value. This would reduce the access to:

mov al,[bp+x]

Edit:

Perhaps I should explain my reason for moving this thread to the 16 bit DOS Programming forum. The primary difference between 16-bit code and 32-bit code is the size of the offset addresses: 16 bits for 16-bit code and 32 bits for 32-bit code. So code that uses 16-bit registers to address memory would, at least normally, be 16-bit code. For example, if I attempt to assemble this source:

.486                  ; create 32 bit code
.model flat, stdcall  ; 32 bit memory model
.data
.code
start:
    mov eax, [bx]
end start


MASM returns:

C:\masm32\My\_TRY\1632.asm(6) : error A2155: cannot use 16-bit register with a 32-bit address

eschew obfuscation