Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quick DEBUG question... DS & ES

Status
Not open for further replies.

CubeE101

Programmer
Nov 19, 2002
1,492
US
Ok... I haven't used debug in forever, and not a whole lot when I did ;-)

I just noticed recently noticed you can't use Segments like...

MOV AX,DS:[SI]
MOV ES:[DI],AX


but you can use...
DS:
-and-
ES:
by them selfs...

So to do the above move commands would you say...

DS:
MOV AX,[SI]
ES:
MOV [DI],AX


If so, do you have to switch to es: everytime you want to address from it, or does it stay current until you switch back?

also, what is the default?
SS:
-or-
DS:

Thanks,
-JS-

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Also...

Are there only 2 ways to perform bit shift operations?

SHL AX, 1
or
SHL AX, CL

where you can't say...

SHL AX, 2

or any other number unless you say...

Mov CL, 2
SHL AX, CL

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
CubeE101,

Do you mean DOS DEBUGGER ? If that's what you mean, there are some primitive rules/limitation that you must follow, because I think it never had an enhancement since 8088 (I might be wrong :) )

1. When you use pointer such [SI], it always pointed (default) by DS, unless you tell it to get from other segment for EACH instruction.
So:

MOV AX,[SI] ; DS:[SI]
ES:
MOV [DI],AX ; ES:[SI]
MOV AX,[SI+2] ; DS:[SI+2]


If you need to stay on ES for several instruction, you better mov ES value to DS.

PUSH DS ; save DS

PUSH ES
POP DS
; Do something

- or -

MOV AX,ES
MOV DS,AX
; Do something

POP DS ; restore DS


2. Shift instruction operand can only use CL for value bigger than 1. So it is only CL or 1

Hope it helps



-- AirCon --
 
You can use

SAR BX,4

for 186, 286 and above.

The immediate value can be any 8 bit value, though apparently only the lower 5 bits are significant.

Similarly for the other shift instructions.

rgds
Zeit.
 
Zeit's absolutely right. But it doesn't really matter about only the lower 5 bits being significant, because the high bits would still just shift the number off the end of the register.
Incidentally, I've heard that on some processors the multiple shift version is actually a teeny teeny bit faster than the single shift version, so under some very very odd circumstances you might want to choose it deliberately even if you're only shifting by 1.
(Don't forget add ax, ax as another useful tool for shifting left 1 bit, and remember scaled index bytes if that's why you're shifting)
 
Zeit,

My machine is Athlon XP2000+, OS-Win ME.
In the DOS debugger, I type in: SAR BX,4. ERROR !!

So..??? I'm a little confuse here

-- AirCon --
 
Ah! You mean the built in assembler in debug!

At a guess that's still stuck in 8088 mode.

Can't see any instruction to enable another processor.
(If you type ? at the - prompt in debug, it gives the available commands).

If you are using Masm, the .286, .386, .486 directives control processor type.


rgds
Zeit.
 
Zeit,

I guess that's what CubeE original question. That's why I mentioned at my first replied.

If he use a compiler, I guess he won't get error for his instruction, or he will get one ?

MOV AX,DS:[SI]
MOV ES:[DI],AX


-- AirCon --
 
I think that using

ES:

or

DS:

in debug generates an instruction prefix.

rgds
Zeit
 
If you're really, really desperate, you can just insert the segment prefix by hand as a db, and then write the instruction as though it weren't that segment. I've done that in Turbo Pascal, which had (has!) a nice built in assembler that sadly stops at 286-level. You can bung in the prefix for overriding size and do a 32-bit instruction dressed up as a 16 bit that way (costs a cycle though). But it doesn't make for readable code. Not recommended.
 
Yup.

mov es:[di],ax

generates a prefix of 026h with MASM.

mov ax,ds:[si]

didn't generate a prefix.

Interesting.

rgds
Zeit.

 
You that's interesting. Funny that I never noticed about these things before either :-D

-- AirCon --
 
I suspect that 80*86 assembler is so complex that a lot of things get buried by the assembler.

I can still remember the shock I had when I started working with it.

And that was after years of working with 8080, z80, and 8085.

Bring back the Intel Blue Box!

On second thoughts, don't bother, don't think you can get the floppy disks any more.

rgds
Zeit.
 
Yes,

I am using the old DEBUG.COM that was included on ever DOS version since dirt was invented ;-)

I do have several High End Assemblers such as Tasm and Masm but I have been going through a tutorial explaining how the PC uses 80x86 OP Codes...

I was using DEBUG because it gives real time fead back of the Hex Codes as you type in the code...

Such as if you type...

A (assemble)
MOV DS,AX
MOV ES,BX
DS:
MOV DX,[SI]
ES:
MOV [DI],DX

U (unassemble)

It will return the opcodes in Hex...
Code:
8ED8  MOV DS,AX
8EC3  MOV ES,BX
3E    DS:
8B14  MOV DX,[SI]
26    ES:
8915  MOV [DI],DX

Although they are of no use unless they are converted to Octal ;-)

Anyways...

I was going through this tutorial...

And I realized there was no way possible, from the definition of the opcodes, to use move with ES (or FS or GS for that matter)

I also have a list of all the opcodes with the assembly code equivalents that DEBUG recognizes...

I dumped that list into an excel spread sheet and only found ES in a few places, but nowhere associated with an address...

Then I tried it in debug, by saying...
Mov ES:[di],AX
And it errored out at the colon...

Then I stumbled accross the...
ES:
CS:
SS:
DS:

commands, and their respective Op Codes...
26 hex or 046 oct
2E hex or 056 oct
36 hex or 066 oct
3E hex or 076 oct

So, I was wondering if these were a switch or prefix for the operation(s) that follows...

So if you assemble
MOV ES:[DI],DX
in TASM/MASM does it return...
26 89 15
For the Opcodes?

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
I use MASM 6.11

MOV ES:[DI],DX

Compiled to:

26 89 15


-- AirCon --
 
Yes, it generates 26 89 15 in MASM.

So you seem to have answered your own question...

rgds
Zeit.
 
Oh... (whoops [neutral]) I guess I skipped a section ;-)

as per the tutorial in the above link...

TABLE 1a: 16-BIT ADDRESSING MODE (x, m) for the expansion impaired. :)
Code:
xm    Eb/Ew         xm    Eb/Ew              xm    Eb/Ew              xm Eb/Ew
00    DS:[BX + SI]  10 Dc DS:[BX + SI + Dc]  20 Dw DS:[BX + SI + Dw]  30 AL/AX
01    DS:[BX + DI]  11 Dc DS:[BX + BI + Dc]  21 Dw DS:[BX + DI + Dw]  31 CL/CX
02    SS:[BX + SI]  12 Dc SS:[BP + SI + Dc]  22 Dw SS:[BP + SI + Dw]  32 DL/DX
03    SS:[BX + DI]  13 Dc SS:[BP + DI + Dc]  23 Dw SS:[BP + DI + Dw]  33 BL/BX
04    DS:[SI]       14 Dc DS:[SI + Dc]       24 Dw DS:[SI + Dw]       34 AH/SP
05    DS:[DI]       15 Dc DS:[DI + Dc]       25 Dw DS:[DI + Dw]       35 CH/BP
06 Dw DS:[Dw]       16 Dc SS:[BP + Dc]       26 Dw SS:[BP + Dw]       36 DH/SI
07    DS:[BX]       17 Dc DS:[BX + Dc]       27 Dw DS:[BX + Dw]       37 BH/DI

Operands where x is 0, 1, or 2 are all pointers. If the instruction is a WORD
instruction (211, 213, 214, 216 are), then this pointer addresses a
word-sized object. The format of the object at the indicated address will
always be low-order byte first, and high-order byte second. Otherwise the
instruction is a BYTE instruction (210, 212) and the pointer addresses
byte-sized object at the indicated address.

The default segments (DS:, SS:) can be overridden with a segment prefix. In
all cases it's understood that everything has the default segment DS, except
for the two stack/frame pointers (BP and SP) whose default segment is SS.
That will be explained below.


So... In short:
DS is the default segment if DI or SI is used
SS is the default segment if SP or BP is used

But they can be overridden with these prefix bytes:
26 (ES:)
2E (CS:)
36 (SS:)
3E (DS:)

Also, the difference between SAR/SAL and SHR/SHL is:
SAR and SAL preserve the sign bit...
SHR and SHL do not preserve the sign bit...

so if SAR is faster than SHR, it might be 1/8 or 1/16 times faster ;-)
(due to the fact it has 1 less bit to deal with :))

I used TASM and assembled SHL AX, 8 ...
it only works if you use .386 in the header...
So I guess in 286 modes (like with debug) you can not use
SHL AX, 8
unless you say
PUSH CX
MOV CL, 8
SHL AX, CL
POP CX
or
SHL AX, 1
SHL AX, 1
SHL AX, 1
SHL AX, 1
SHL AX, 1
SHL AX, 1
SHL AX, 1
SHL AX, 1

Also the prefixes for FS and GS are...
FS - 64h
GS - 65h

if anyone is curious ;-)

Thanks,
-JS

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
That's very complete.

Thanks.

And we haven't even thought about protected mode yet...
rgds
Zeit.
 
What exactly is Protected Mode???

Does WinXP support Protected mode...

I know DJGPP (GNU GCC C/C++ Compiler) used this 32 bit Protected mode, but none of it's programs seem to run on XP...

(Maybe XP stands for eXclude Protected-mode ;-))

I did notice, in one of the many asm tutorials I have D/L'ed over the years, that it did say something about FS and GS being required or used with Protected Mode...

So what is the difference between Real mode and Protected???

Thanks,
- J S -

M E R R Y C H R I S T M A S

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Real mode is 8086 mode. They all come out of reset in real mode.

Protected mode is available on the 286 and above and changes the way various registers operate.

I've never used protected mode in assembler.

This site:


shows the murky history of Windoze.

So far as I can see Windows has been protected mode since 3.1 and provides a DPMI (dos protected mode interface) in a dos box.

This is now beyond my competence to discuss really.
rgds
Zeit.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top