about org 100h

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
jimson

about org 100h

Post by jimson »

i wish to know
why org 100h doesn't generate machine code yet it can affect the value of string when we mov si, string1?
(by adding 100h to the address of string1?)

how org 100h works?
Schol-R-LEA

Re:about org 100h

Post by Schol-R-LEA »

jimson wrote: i wish to know
why org 100h doesn't generate machine code yet it can affect the value of string when we mov si, string1?
(by adding 100h to the address of string1?)

how org 100h works?
This might be better in the General Programming board, but...

The ORG (origin) statement is an assembler directive that causes the the assembler to begin the assembly at the given segement offset. This means that, given the following code:

Code: Select all

[BITS 16]              ; generate 16-bit real-mode machine code
[ORG 0x0100]           ; .com files always begin at offset 100 hex

main:???
    mov dx, hellomsg   ; copy a pointer to the beginning of hellomsg into register dx
    mov ah,  9         ; pass the number of the DOS function to use
    int 0x021          ; call DOS using interrupt 21 hex

    mov ax, 0x04C00    ; This DOS function exits the program
    int 0x021          ; and returns control to DOS.


hellomsg db "Hello, World!", 0DH,0AH,'$' 
; "Hello, World!" plus a carriage return and line feed
... then the segment offset address of 'main' is 0x0100, while that of 'hellomsg' is 0x010C. Here's a full breakdown of the addresses and opcode values:

Code: Select all

address(in hex)? ?opcode??argument
---------------------------------  
0000              BA      0C 00
                  mov dx, address of hellomsg - note that the bytes are reversed!

0003              B4      09
                   mov ah, 9 hex (same as 9 decimal, of course)

0005              CD      21
                  INT     21 hex

0007              B8      00 4C
                  mov AX, 4C00 hex - note that the bytes are reversed again

000A              CD      21
                  INT     21 hex

address?????      data
-----------------------          
000C              48 65 6C 6C 6F 2C 20 57 6F 72 6C 64 21 0D 0A 24     
                  H  e  l  l  o  ,      W  o  r  l  d  ! CR LF  $
HTH. C&CW.
Post Reply