(C5) LDS opcode

Programming, for all ages and all languages.
Post Reply
sidewinder58
Posts: 3
Joined: Mon Aug 27, 2012 6:30 am

(C5) LDS opcode

Post 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...
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: (C5) LDS opcode

Post 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
Last edited by bluemoon on Mon Aug 27, 2012 7:28 am, edited 3 times in total.
sidewinder58
Posts: 3
Joined: Mon Aug 27, 2012 6:30 am

Re: (C5) LDS opcode

Post 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.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: (C5) LDS opcode

Post by bluemoon »

The +2 come from the pointer structure, as defined at IA manual Volume#1, Section 4.3 POINTER DATA TYPES.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: (C5) LDS opcode

Post by qw »

bluemoon wrote:EDIT: fixed typo
You should fix again: DX:=OLD_DS:[BX+SI], DS:=OLD_DS:[BX+SI+2].
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: (C5) LDS opcode

Post by bluemoon »

Thanks for the correction, I haven't use LDS since DOS time.
sidewinder58
Posts: 3
Joined: Mon Aug 27, 2012 6:30 am

Re: (C5) LDS opcode

Post 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
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: (C5) LDS opcode

Post by qw »

b
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: (C5) LDS opcode

Post by Nable »

I'll just leave it here one more time: ftp://mipt.cc/Opcode.txt
Post Reply