1

I am trying to figure out an MBR code (16-bit assembly code in real mode) and I have these lines :

mov    si,0x7cd8
lods   al,BYTE PTR ds:[si]

What happens in real time, is that the physical address is 'D8' - How do I know that ? Because this is used for loading a string and printing it to the string. and that`s the first thing I can see when I run this program and these are the first lines of the code.

My question is about the second line, is it that the physical address I get is because of the calculation being done to get the physical address (segment * 16 + offset) or that the BYTE PTR tells that the SI address will be type of BYTE and the type of the data we will read is of type byte ?

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
sitoNz
  • 93
  • 2
  • 9
  • 2
    The type doesn't matter, it's because of `segment*16+offset`. The physical address is `0x7cd8` with `ds=0` or else it wouldn't work ;) – Jester Nov 28 '16 at 20:43
  • The `BYTE PTR` is only required when the target size is not evident. And your `lods ...` is more usually written as `lodsb`. Finally, `ds` is the default segment register for `lodsxx` anyway, so the segment override is unnecessary. – Weather Vane Nov 28 '16 at 20:58

1 Answers1

3

The second line

lods   al,BYTE PTR ds:[si]

is simply the disassemblers output of the instruction LODSB(load a byte from the address DS:SI and INC SI).

In assembler you would simple write LODSB which means

load a byte from the address DS:SI to the byte register AL and increment SI afterwards

Concerning the segment issue of DS: of course the accessed address is calculated by the formula (segment * 16 + offset), but you can set DS to anything you want and only SI is incremented (post-read) by the instruction, nevertheless.

DS can have any value.

zx485
  • 28,498
  • 28
  • 50
  • 59
  • I understand now. Concerning DS is not being changed thorugh all the program manually, it will always stay 0 (default) ? – sitoNz Nov 28 '16 at 21:13
  • 3
    @sitoNz: I (seriously) don't know. The value of `DS` will surely be defined somewhere before these two lines are executed. Assuming a default value would be (very) bad practice in a MBR. – zx485 Nov 28 '16 at 21:17