Page 1 of 1

(C5) LDS opcode

Posted: Mon Aug 27, 2012 6:43 am
by sidewinder58
Hi guys

I'm busy reading through some assembly code and trying to understand what the opcodes are doing. I ran into opcode C5 with no prefixes which is LDS /r.

The modr/m byte is &H10 (00-010-000), which gives me DX from the reg field (010) and [BX+SI] from the mod (00) and r/m (000) fields.

The intel manual says that the default segment register is SS for effective addresses containing a BP index, and DS for other effective addresses.

I'm having trouble firguring out what the address pointer is supposed to be. Is it DS:[BX+SI]? Cos then that would mean that DS stays the same (or is loaded with the same value again) and DX is loaded with [BX+SI], wouldn't it?

Please help me understand this...

Re: (C5) LDS opcode

Posted: Mon Aug 27, 2012 7:04 am
by bluemoon
The manual says:
Loads a far pointer (segment selector and offset) from the second operand (source
operand) into a segment register and the first operand (destination operand). The
source operand specifies a 48-bit or a 32-bit pointer in memory depending on the
current setting of the operand-size attribute (32 bits or 16 bits, respectively).
So, if the current op size is 16-bit, it's DS:=OLD_DS:[BX+SI], DX:=OLD_DS:[BX+SI+2]

EDIT: fixed typo

Re: (C5) LDS opcode

Posted: Mon Aug 27, 2012 7:20 am
by sidewinder58
Thanks very much for the response. Still not sure how you got to those values.

By my calculation, the current value for BX would be &H0000 and SI would be &H7E00. The byte code looks like this C5 10 E2 F4. I don't understand where the +2 comes from. Presumably some immediate value? imm8/imm16?

I don't get how that works then either because it doesn't specify any immediate values in the manual ... does it?

EDIT: To give context to the whole endeavour, the source file is a boot sector.

Re: (C5) LDS opcode

Posted: Mon Aug 27, 2012 7:24 am
by bluemoon
The +2 come from the pointer structure, as defined at IA manual Volume#1, Section 4.3 POINTER DATA TYPES.

Re: (C5) LDS opcode

Posted: Mon Aug 27, 2012 8:54 am
by qw
bluemoon wrote:EDIT: fixed typo
You should fix again: DX:=OLD_DS:[BX+SI], DS:=OLD_DS:[BX+SI+2].

Re: (C5) LDS opcode

Posted: Mon Aug 27, 2012 9:47 am
by bluemoon
Thanks for the correction, I haven't use LDS since DOS time.

Re: (C5) LDS opcode

Posted: Mon Aug 27, 2012 2:44 pm
by sidewinder58
So then, if BX = 0000 and SI = 7E00, should my values be:

a)
DS = 7E00
DX = 7E02

or
b)
DS = 16-bit value at OLD_DS:[BX+SI+2] = 0000
DX = 16-bit value at OLD_DS:[BX+SI] = 0000

Re: (C5) LDS opcode

Posted: Wed Aug 29, 2012 4:28 am
by qw
b

Re: (C5) LDS opcode

Posted: Thu Aug 30, 2012 12:41 pm
by Nable
I'll just leave it here one more time: ftp://mipt.cc/Opcode.txt