xchgb at masterboot - Minix

This is a discussion on xchgb at masterboot - Minix ; Hi all: I'm stock at understanding the partition entries sorting in masterboot, the comfused points to me are: #1123: why ch? what value it contains, 0? #1130: what the "(register)" expression means, operate on the register's address? #1130 ~ #1135 ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: xchgb at masterboot

  1. xchgb at masterboot

    Hi all:
    I'm stock at understanding the partition entries sorting in
    masterboot, the comfused points to me are:
    #1123: why ch? what value it contains, 0?
    #1130: what the "(register)" expression means, operate on the
    register's address?
    #1130 ~ #1135 can somebody elaborate on those lines?
    #1137: what this line suppose to mean?

    1123 cmpb sysind(si), ch ! Partition type,
    nonzero when in use
    1124 jz exchg ! Unused entries sort
    to the end
    1125 inuse: mov bx, lowsec+0(di)
    1126 sub bx, lowsec+0(si) ! Compute di->lowsec -
    si->lowsec
    1127 mov bx, lowsec+2(di)
    1128 sbb bx, lowsec+2(si)
    1129 jnb order ! In order if si-
    >lowsec <= di->lowsec

    1130 exchg: movb ah, (si)
    1131 xchgb ah, PENTRYSIZE(si) ! Exchange entries
    byte by byte
    1132 movb (si), ah
    1133 inc si
    1134 cmp si, di
    1135 jb exchg
    1136 order: mov si, di
    1137 cmp si, #BUFFER+PART_TABLE+3*PENTRYSIZE
    1138 jb bubble
    1139 loop sort
    1140 mov si, bp ! si = sorted
    table
    1141 movb ah, #PENTRYSIZE
    1142 mulb ah ! ax = al *
    PENTRYSIZE
    1143 add si, ax ! si = address of
    partition entry
    1144 cmpb sysind(si), #1 ! Should be in use
    1145 jb error0
    1146 jmp loadpart ! Get the partition
    bootstrap


  2. Re: xchgb at masterboot

    leon800219@gmail.com wrote:
    > Hi all:
    > I'm stock at understanding the partition entries sorting in
    > masterboot, the comfused points to me are:
    > #1123: why ch? what value it contains, 0?


    ch is the high byte of cx; cl is the low byte. The ACK assembler requires you
    to use 'XXXb' forms of the instructions to do byte accesses, too.

    > #1130: what the "(register)" expression means, operate on the
    > register's address?


    It means to indirect via the value in the register, so (si) means to operate
    on the value at address si. 5(si) means to operate on the value at si+5.
    (There's also a form that allows you to operate on register+register*constant,
    but I forget what it is right now.)

    > #1130 ~ #1135 can somebody elaborate on those lines?


    > 1130 exchg: movb ah, (si)
    > 1131 xchgb ah, PENTRYSIZE(si)
    > 1132 movb (si), ah
    > 1133 inc si
    > 1134 cmp si, di
    > 1135 jb exchg


    Gosh. That's freaky. I think it translates to:

    1130 ah = *si;
    1131 swap(si[PENTRYSIZE], ah);
    1132 *si = ah;
    1133 si++;
    1134-5 if (si < di) goto 1130

    It's swapping the contents of the partition structure at si with the partition
    structure at si+PENTRYSIZE (i.e., the next one).

    > #1137: what this line suppose to mean?


    > 1137 cmp si, #BUFFER+PART_TABLE+3*PENTRYSIZE


    # marks a literal value. So all it's doing is comparing si with the constant
    (BUFFER+PART_TABLE+3*PENTRYSIZE).

    I hate x86 assembly.

    --
    ┌── dg*cowlark.com ─── http://www.cowlark.com ──────────────── ──
    │ "Wizards get cranky, / Dark days dawn, / Riders smell manky, / The road
    │ goes on. / Omens are lowering, / Elves go West; / The Shire needs
    │ scouring, / You may as well quest." - John M. Ford

  3. Re: xchgb at masterboot

    In article ,
    David Given wrote:
    >leon800219@gmail.com wrote:
    >> Hi all:
    >> I'm stock at understanding the partition entries sorting in
    >> masterboot, the comfused points to me are:
    >> #1123: why ch? what value it contains, 0?

    >
    >ch is the high byte of cx; cl is the low byte. The ACK assembler requires you
    >to use 'XXXb' forms of the instructions to do byte accesses, too.


    And it happens to be zero at that point. I should have used #0, but
    that costs one byte extra and that particular version of masterboot
    only had a few bytes to spare. So making it small mattered much more
    than making it look good.
    --
    Kees J. Bot, Systems Programmer, Sciences dept., Vrije Universiteit Amsterdam

  4. Re: xchgb at masterboot

    On 38, 6ʱ39, David Given wrote:
    > leon800...@gmail.com wrote:
    > > Hi all:
    > > I'm stock at understanding the partition entries sorting in
    > > masterboot, the comfused points to me are:
    > > #1123: why ch? what value it contains, 0?

    >
    > ch is the high byte of cx; cl is the low byte. The ACK assembler requiresyou
    > to use 'XXXb' forms of the instructions to do byte accesses, too.
    >
    > > #1130: what the "(register)" expression means, operate on the
    > > register's address?

    >
    > It means to indirect via the value in the register, so (si) means to operate
    > on the value at address si. 5(si) means to operate on the value at si+5.
    > (There's also a form that allows you to operate on register+register*constant,
    > but I forget what it is right now.)
    >
    > > #1130 ~ #1135 can somebody elaborate on those lines?
    > > 1130 exchg: movb ah, (si)
    > > 1131 xchgb ah, PENTRYSIZE(si)
    > > 1132 movb (si), ah
    > > 1133 inc si
    > > 1134 cmp si, di
    > > 1135 jb exchg

    >
    > Gosh. That's freaky. I think it translates to:
    >
    > 1130 ah = *si;
    > 1131 swap(si[PENTRYSIZE], ah);
    > 1132 *si = ah;
    > 1133 si++;
    > 1134-5 if (si < di) goto 1130
    >
    > It's swapping the contents of the partition structure at si with the partition
    > structure at si+PENTRYSIZE (i.e., the next one).
    >
    > > #1137: what this line suppose to mean?
    > > 1137 cmp si, #BUFFER+PART_TABLE+3*PENTRYSIZE

    >
    > # marks a literal value. So all it's doing is comparing si with the constant
    > (BUFFER+PART_TABLE+3*PENTRYSIZE).
    >
    > I hate x86 assembly.
    >
    > --
    > 룮 http://www.cowlark.com...
    > "Wizards get cranky, / Dark days dawn, / Riders smell manky, / Theroad
    > goes on. / Omens are lowering, / Elves go West; / The Shire needs
    > scouring, / You may as well quest." - John M. Ford


    Thanks, You did help me clarifying things. But one thing I still
    unclear, xchgb
    It seems to me the "xchgb ah, PENTRYSIZE(si)" boils down to "xchgb
    mem, constant", Is that right?


  5. Re: xchgb at masterboot

    leon800219@gmail.com wrote:
    [...]
    > Thanks, You did help me clarifying things. But one thing I still
    > unclear, xchgb
    > It seems to me the "xchgb ah, PENTRYSIZE(si)" boils down to "xchgb
    > mem, constant", Is that right?


    No, it's 'xchb register, contents of si+constant'. Other assemblers usually
    express this as something like 'xchg ah, [si+PENTRYSIZE]'.

    --
    ┌── dg*cowlark.com ─── http://www.cowlark.com ──────────────── ──
    │ "Wizards get cranky, / Dark days dawn, / Riders smell manky, / The road
    │ goes on. / Omens are lowering, / Elves go West; / The Shire needs
    │ scouring, / You may as well quest." - John M. Ford

  6. Re: xchgb at masterboot

    David Given wrote:
    > leon800219@gmail.com wrote:
    > [...]
    >> Thanks, You did help me clarifying things. But one thing I still
    >> unclear, xchgb
    >> It seems to me the "xchgb ah, PENTRYSIZE(si)" boils down to "xchgb
    >> mem, constant", Is that right?

    >
    > No, it's 'xchb register, contents of si+constant'. Other assemblers usually
    > express this as something like 'xchg ah, [si+PENTRYSIZE]'.
    >


    Other assemblers also accept 'xchg ah, PENTRYSIZE[si]'.
    But IIRC 'xchg ah, [si+PENTRYSIZE]' is accepted in Minix - al least
    for 16 bits instruction set.

    Ciao
    Giovanni
    --
    A computer is like an air conditioner,
    it stops working when you open Windows.
    Registered Linux user #337974 < http://giovanni.homelinux.net/ >

+ Reply to Thread