1

I wrote a asm program it begins like this:

org 0100h
mov ax,cs
mov ds,ax
mov es,ax

But when I look at the program with winhex,the address is not 0100h.Could anyone tell me why?

maple
  • 1,828
  • 2
  • 19
  • 28

2 Answers2

0

I am going to quote Paul R and Michael Chourdakis from this question

"ORG is used to set the assembler location counter. This may or may not translate to a load address at link time."

"ORG is merely an indication on where to put the next piece of code/data, related to the current segment.

It is of no use to use it for fixed addresses, for the eventual address depends on the segment which is not known at assembly time."

GuidedHacking
  • 3,628
  • 1
  • 9
  • 59
0

If you look at the program in a hex editor it's not going to necessarily be at address 0x100. But let's look at a sample program here:

.code
org 100h

nop
mov ax,@code
mov ds,ax          
mov si,100h
lodsb              ;AL should be 0x90, the opcode for NOP.

Now that's assuming there's no linker or relocation magic going on behind the scenes (and on modern computers there usually is.) If you were programming an 8-bit CPU the org directive is usually literally the address of the first line of actual code.

puppydrum64
  • 1,598
  • 2
  • 15