Can anybody tell me what the ORG does in TASM? i know the ORG 100h in ".COM" files and why we put it there (PSP) but i saw this code the other day which was something like this:


Posted on 2006-08-25 03:09:42 by XCHG
ORG is used to set the assembler's location counter (LC). This LC variable is incremented by the size of the opcode during each translation. So ORG 100h simply sets the LC variable to 256 (the number of bytes from the beginning of the .com file that the entry point is located).

In NASM and MASM (and probably TASM), the $ signifies the current LC value. So $-2 would be the current LC value minus 2 bytes. I'm not exactly sure about TASM, but if you do this code in NASM it would overwrite the INT 21h instruction with the instruction that follows, as though that instruction doesn't exist. This is because the INT 21h instruction is 2 bytes long (0CD21h). Although there might be a different meaning for $ in TASM, so I'll wait for someone to confirm or disprove me.

Regards,
Bryant Keller
Posted on 2006-08-25 09:45:08 by Synfire
You're right, Synfire.

BTW: XCHG, I hope you're using at least TASM5.0 (version 5.2 supports pentium instructions along with MMX). Earlier TASMs are severly bugged. Yet it is a great assembler with very nice (IMHO) OOP suuport :)
Posted on 2006-08-25 14:09:21 by ti_mo_n
P.S:
This code vaild for tasm/masm
Org 123
bla bla bla
Org 456
more bla bla bla

But It's invalid for Nasm
Posted on 2006-08-25 16:39:33 by Dite

P.S:
This code vaild for tasm/masm
Org 123
bla bla bla
Org 456
more bla bla bla

But It's invalid for Nasm


The second ORG will just be ignored, ORG is a one-shot deal in NASM as you are supposed to use it at the beginning of a source file to define the base address of the program.
Posted on 2006-08-25 20:27:13 by SpooK


P.S:
This code vaild for tasm/masm
Org 123
bla bla bla
Org 456
more bla bla bla

But It's invalid for Nasm


The second ORG will just be ignored, ORG is a one-shot deal in NASM as you are supposed to use it at the beginning of a source file to define the base address of the program.


If NASM only lets you use it once, how do you accomplish the same functionality?

Although it's not very often that it's useful to use org repeatedly in average programs, my OS code needs that capability.  I use MASM, and it does work, but it'd be nice if I could use NASM too.
Posted on 2006-08-26 01:54:49 by hackulous
http://nasm.sourceforge.net/doc/html/nasmdo10.html

10.1.3 ORG Doesn't Work

People writing boot sector programs in the bin format often complain that ORG doesn't work the way they'd like: in order to place the 0xAA55 signature word at the end of a 512-byte boot sector, people who are used to MASM tend to code

        ORG 0

        ; some boot sector code

        ORG 510
        DW 0xAA55

This is not the intended use of the ORG directive in NASM, and will not work. The correct way to solve this problem in NASM is to use the TIMES directive, like this:

        ORG 0

        ; some boot sector code

        TIMES 510-($-$$) DB 0
        DW 0xAA55

The TIMES directive will insert exactly enough zero bytes into the output to move the assembly point up to 510. This method also has the advantage that if you accidentally fill your boot sector too full, NASM will catch the problem at assembly time and report it, so you won't end up with a boot sector that you have to disassemble to find out what's wrong with it.
Posted on 2006-08-26 06:07:36 by Dite
Oh okay so this is what i wrote:

.DATA
  String1      DB        'Assembly', 0
; ------------------------------
.CODE
  WriteStr PROC
    PUSH    AX
    PUSH    BX
    PUSH    BP
    MOV    BP  , SP
    MOV    BX ,WORD PTR
    MOV    AH , 0Eh
    OR      AX , AX
    ORG    $-2
    @@__WriteStrLoop:
      DW      10CDh
      MOV    AL , BYTE PTR
      INC    BX
      TEST    AL , AL
      JNE    @@__WriteStrLoop
    POP    BP
    POP    BX
    POP    AX
    RET
  WriteStr ENDP
  ; ------------------------------
  START:
 
    PUSH    OFFSET String1
    CALL    WriteStr
    ADD    SP , 0002h


So i guess i actually saved a few bytes for jumping to the end of the procedure which is now replaced with only one near jump.

Thank you guys.
Posted on 2006-08-26 22:32:53 by XCHG