pointersassemblyx86bootloadermbr

Using BYTE PTR to determine the address size when using Data Segment


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 ?


Solution

  • 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.