News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

How were pointers with segment and offset addresses compared?

Started by bugthis, September 18, 2023, 06:59:24 PM

Previous topic - Next topic

bugthis

How were pointers with segment and offset addresses compared?
In segment offset addressing, different combinations of segment and offset addresses could point to the same linear address.
In order to compare two pointers, did the addresses first have to be converted into linear addresses or was another methodology used?

NoCforMe

Hmm, never done this, but ... seems to me if a guy wanted to compare two segment:offset addresses, the thing to do would be to convert both of them to 20-bit addresses, which is what the processor does to resolve the address. Not exactly sure how to do that, but shouldn't be too difficult with some double-word operations.

Just off the top of my head, how about this?
    MOV    DX, seg
    MOV    CL, 12
    SHR    DX, CL        ;Get high nybble of segment in DX.
    MOV    AX, seg
    MOV    CL, 4
    SHL    AX, CL        ;12 low bits of segment + 0000
    ADD    AX, off
    ADC    DX, 0        ;Add in any carry to high nybble.

Should give you a normalized 20-bit address in DX:AX.
Assembly language programming should be fun. That's why I do it.

daydreamer

Simplest is Cmp ax,bx in. Com file before you start to change segment registers ss,ds,cs,es, they are the same
Sp and/or BP registers use ss = stack segment
Special usage
When using lodsb, Stosb, movsb it's si using ds as source,while di using es destination
segment registers * 16 compared to ax,bx,cx,dx,Di,si
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

Rockphorr

ds:si = ptr


mov BX,DS
mov AX,SI
shr AX,1
shr AX,1
shr AX,1
shr AX,1
add BX,AX
mov AX,SI
and AX,000Fh

so we get seg:ofs in BX:AX where ofs<10h
compare seg1 and seg2 than compare ofs1 and ofs2




Rockphorr

Quote from: NoCforMe on September 20, 2023, 04:45:52 PMHmm, never done this, but ... seems to me if a guy wanted to compare two segment:offset addresses, the thing to do would be to convert both of them to 20-bit addresses, which is what the processor does to resolve the address. Not exactly sure how to do that, but shouldn't be too difficult with some double-word operations.

Just off the top of my head, how about this?
    MOV    DX, seg
    MOV    CL, 12
    SHR    DX, CL        ;Get high nybble of segment in DX.
    MOV    AX, seg
    MOV    CL, 4
    SHL    AX, CL        ;12 low bits of segment + 0000
    ADD    AX, off
    ADC    DX, 0        ;Add in any carry to high nybble.

Should give you a normalized 20-bit address in DX:AX.

good solution even for UMB like DS=0FFFFh and SI>2