Author Topic: problem for "address"  (Read 15533 times)

nobody

  • Guest
problem for "address"
« on: November 14, 2007, 03:55:32 AM »
part of my codes (Just for learning ProtectMode):

%macro Descriptor 3
   dw   %2 & 0FFFFh
   dw   %1 & 0FFFFh
   db   (%1 >> 16) & 0FFh
   dw   ((%2 >> 8) & 0F00h) | (%3 & 0F0FFh)
   db   (%1 >> 24) & 0FFh
%endmacro

DA_32      EQU   4000h
DA_DRW      EQU   92h
DA_C      EQU   98h   


org   0100h
   jmp   LABEL_BEGIN

[SECTION .gdt]
; GDT
;
LABEL_GDT:      Descriptor          0,                0, 0
LABEL_DESC_CODE32:   Descriptor          0, SegCode32Len - 1, DA_C + DA_32
LABEL_DESC_VIDEO:   Descriptor          0B8000h,           0ffffh, DA_DRW
; GDT END

GdtLen      equ   $ - LABEL_GDT   ; GDT  LEN
GdtPtr      dw   GdtLen - 1
      dd   0      

; GDT SELECTOR
SelectorCode32      equ   LABEL_DESC_CODE32   - LABEL_GDT
SelectorVideo      equ   LABEL_DESC_VIDEO   - LABEL_GDT
; END of [SECTION .gdt]

[SECTION .s16]
[BITS   16]
LABEL_BEGIN:
   mov   ax, cs
   mov   ds, ax
   mov   es, ax
   mov   ss, ax
   mov   sp, 0100h

; INITIA
   xor   eax, eax
   mov   ax, cs
   shl   eax, 4
   add   eax, LABEL_SEG_CODE32
   mov   word [LABEL_DESC_CODE32 + 2], ax
   shr   eax, 16
   mov   byte [LABEL_DESC_CODE32 + 4], al
   mov   byte [LABEL_DESC_CODE32 + 7], ah
......
I debuger the file with td and get the following codes

1.   xor eax,eax
2.   mov ax,cs
3.   shl eax,0x4
4.   add eax,0x180
5.   mov [0x10e],ax
6.   shr eax,0x10
7.   mov [0x110],al
8.   mov [0x113],ah

in line 4.  I get "LABEL_SEG_CODE32 = 0x180"
and in line 5.  get "LABEL_DESC_CODE32 + 2 =  0x10e"
but all know "0x180 + 2 != 0x10e"
why??????
who can explain it.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: problem for "address"
« Reply #1 on: November 14, 2007, 05:50:22 AM »
I see three undefined symbols. Please post the real code.


...
   add   eax, LABEL_SEG_CODE32
   mov   word [LABEL_DESC_CODE32 + 2], ax

...
4.   add eax,0x180
5.   mov [0x10e],ax

...
in line 4.  I get "LABEL_SEG_CODE32 = 0x180"
and in line 5.  get "LABEL_DESC_CODE32 + 2 =  0x10e"
but all know "0x180 + 2 != 0x10e"
why??????

"Why?" Because it isn't! Why do you think "LABEL_DESC_CODE32" ought to be the same as the missing "LABEL_SEG_CODE32"?

I strongly suspect your problem stems from using multiple sections. What are you trying to do?

Best,
Frank