Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

LABEL directive

hello,

could someone please describe me what LABEL directive is used for?

any example?

MASM/TASM seem to support this directive, emu8086 does not...

«1

Comments

  • BitdogBitdog Member Posts: 528
    : hello,
    :
    : could someone please describe me what LABEL directive is used for?
    :
    : any example?
    :
    : MASM/TASM seem to support this directive, emu8086 does not...
    :
    :

    ALABEL:

    MOV DX,ALABEL ; DX holds the labels address, Nasm
    MOV DX,OFFSET ALABEL ; DX holds the labels address, Masm

    A label is the offset of the segment it is in, CS:ALABEL or DS:ALABEL etc

    A label can be as follows:
    ALABEL DB 13,10
    once again it is a word assigned to an address, or you make up a word,
    use it as a label, and then can address that address using your word/label. (word is not used as word/byte, but as in a sentence)

    You can start a procedure with a LABEL: and jump or call that label
    CALL ALABEL ; requires RET at then end of your proc code.
    JMP ALABEL ; jumps with in 0xFFFF distance in either direction.
    JMP SHORT ALABEL ; jumps 128 bytes in either direction.

    I like to use labels in areas that the code is only used once as
    declaired words or bytes
    CALL ALABEL ; returns AX & CX
    MOV WORD [ALABEL],AX ; store AX at ALABEL if we arn't going to call it again.
    MOV WORD [ALABEL+2],CX ; and why not ?

    Well, I hope that helps somehow.
    Bitdog

  • little_coderlittle_coder Member Posts: 29
    Thank you for your reply Bitdog!

    I'm still confused about this LABEL directive,
    here is a part of the code that I found somewhere:

    [code]
    valptr label byte
    value dw 0fc3h
    mirror dw ?
    array_ptr label byte
    array db 0,128,64,192,32,160,96,224
    db 16,144,80,208,48,176,112,240
    [/code]

    what for the "valprt" maybe used? and is it the same
    if we do this instead:

    [code]
    valptr:
    value dw 0fc3h
    mirror dw ?
    array_ptr:
    array db 0,128,64,192,32,160,96,224
    db 16,144,80,208,48,176,112,240
    [/code]

    Thank you!

  • BitdogBitdog Member Posts: 528
    : I'm still confused about this LABEL directive,
    : here is a part of the code that I found somewhere:
    :
    : [code]
    : valptr label byte
    : value dw 0fc3h
    : mirror dw ?
    : array_ptr label byte
    : array db 0,128,64,192,32,160,96,224
    : db 16,144,80,208,48,176,112,240
    : [/code]
    :
    : what for the "valprt" maybe used? and is it the same
    : if we do this instead:
    :
    : [code]
    : valptr:
    : value dw 0fc3h
    : mirror dw ?
    : array_ptr:
    : array db 0,128,64,192,32,160,96,224
    : db 16,144,80,208,48,176,112,240
    : [/code]

    The code is a bit different that my assembler uses, but here goes:
    valptr ptr stands for pointer, but valptr: is a label,
    valptr label byte
    is code defining a label as short? as with in 128 bytes of a jumper.
    Labels usually don't have to be defined,
    they are defined with the : on the end as in, valptr:
    Where a label is placed determines it's value/address,
    org 100h ; set end of PSP and start of code in com file
    label1: ; make a label
    db 0 ; declair a byte
    label2: ; make another label
    ok, label1: holds the address of 100h since that's where it's placed,
    label2: holds the address of 100h plus the byte we declaired,= 101h.
    A label holds the address of the beginning of the line.
    The instruction pointer (IP)can goto a label to process the code that
    follows it, by a jump or call instruction.

    When you make up a name for your label, you can't use names the
    assembler/compiler uses as reserved names, but you can add to those
    names and that works. Example: MOV is an asm reserved, but MOVMOV isn't. MOV1 isn't, etc.
    Basic language numbers the lines, so you can jump to a line?
    Asm allows labels so you can, copy/move lines of code and
    no damage is done since the assembler computes the address of labels
    at assembly time.
    A line of asm code: MOV AX,BX
    assembled makes machine code, & that takes up bytes in the .com or .exe file.
    The assembler counts those bytes and when it bumps into a label, it gives the label the address according to where it sits in those bytes.

    LABEL DIRECTIVE, ok directive, an area I know little about, and you probably don't need to know it either. This could be your source of confusion. Throw out the directive part and what have you got.
    A LABEL is all. To me they are easy to understand. But thinking it's a directive or instruction of some kind could cause CONFUSION.
    It's just a name you make up to use as an address holder.
    INDIRECTION
    MOV AX,LABEL ; Nasm
    MOV AX,OFFSET LABEL ; Masm
    AX holds the labels address

    MOV AX,[LABEL] ; Nasm [DS:LABEL]is the full address
    MOV AX,LABEL ; Masm
    AX holds the word that was in memory at that address label points to.
    [LABEL] is the standard for indirection I believe?

    There are standards set for assembly language, most assemblers use those standards, they are simple and work well.
    But the folks who want your money don't tell you that you can use standard calls/instructions on their assembler,
    they tell you their key words and you become familuar with only their style/program and there for always send them your money, cause their program works for you, because you are familuar with it and there fore you can get it to work/do_something.
    You've seen code files that have 10 pages of prototypeing, defines, legal agreements, web site/name bragging, then at the bottom is INT 21h
    and that's it. hahahahahahahaha That's is key word manipulation to own a standard for money crap. DON'T FALL FOR IT.
    LABEL:
    is all you need to make a label that can be called far/near jumped to near/short etc.
    define LABEL extern far MScrap associated/with file1 file2 blablabla
    Label is not a key or reserved word that I know of? (or can remember)
    LABEL1:
    LABEL2:
    works?, I use instructions reserved words as labels
    MOV_LOOP1
    STOSB45:
    ETC:
    HOPE: THAT: HELPS: SOMEHOW:
    Bitdog:



  • davimedradedavimedrade Member Posts: 105
    The label directive is used when you want that some area of the data segment is used as a variable. Using this code:

    .model small
    .code

    msg label byte
    db 'Test of Message',13,10,'$'

    start:
    mov ah,9
    mov dx,offset msg
    push cs
    pop ds
    int 21h
    mov ah,4ch
    int 21h
    end start

    Will print the Test of Message on the display. I dont know why use this instead of:

    msg db 'Test of Message',13,10,'$'

    But it's the same thing.

    Note: This code is for TASM.

    Davi Medrade
    Brazil

  • BitdogBitdog Member Posts: 528
    : The label directive is used when you want that some area of the data segment is used as a variable. Using this code:
    :
    : .model small
    : .code
    :
    : msg label byte
    : db 'Test of Message',13,10,'$'
    :
    : start:
    : mov ah,9
    : mov dx,offset msg
    : push cs
    : pop ds
    : int 21h
    : mov ah,4ch
    : int 21h
    : end start
    :
    : Will print the Test of Message on the display. I dont know why use this instead of:
    :
    : msg db 'Test of Message',13,10,'$'
    :
    : But it's the same thing.
    :
    : Note: This code is for TASM.
    :
    : Davi Medrade
    : Brazil
    :

    Now I'm curious. Does LABEL BYTE
    mean a short jump/call ?
    what does the BYTE mean ?
    What part of my previous rambling was incorrect too ?
    Thankx in advance, Mr. Medrade.

    Sincerely
    ...... Bitdog
    (little bit dog, little bit human)

  • dantygydantygy Member Posts: 1
    : hello,
    :
    : could someone please describe me what LABEL directive is used for?
    :
    : any example?
    :
    : MASM/TASM seem to support this directive, emu8086 does not...
    :
    :
    i am just starting to learn assembly going through 'assemby language step-by-step' book by jeff duntemann which i find as excellent book for starters. here is what i understood :
    A label is a sort of bookmark, holding a place in the program code and giving it a name that's easier to remember than a memory address. Which you can always jump to it to execute instructions starting at that bookmark..Lets look at this Example:

    WriteLabel:
    Mov AH, 09H
    Int 21H
    ret

    what this label does is simply print to the screen what ever data it finds in register AX and return (ret) to the caller to continue where it left off.

    Suppose I wanted a string to be printed and I defined it as so:

    LittleCoder DB example of string to be printed to the monitor, $

    Now if I had a mov instructions that moved LittleCoder into AX and called WriteLabel right after that . assembler will print the string to the screen. And if I had many string to be printed in my program repeatedly, I dont have to write the complete instructions every time like:

    Mov AH, 09H
    Int 21H

    I would only call the WriteLabel instead and the assembler will do the rest of the job of printing the data to the screen. Well, above label is only 2 instruction however. Imagine if you had a code with 10 instructions, which you had to write over and over again in your program. that would be a pain in the A~~. Thats why you would use a label and jump to it in your program as often as you like.

    Do not confuse Label with DB directives.
    the DB directive ordinarily sets aside one byte only somewhere in memory that defines a string. however, a string may be any length you like, as long as it remains on a single line of your source code file ( there are ways to make it more than one line). strings are defined simply by associating a bookmark with the place where the string starts in memory. Example:

    LittleCoder DB 'example of define byte string', "$"

    so, the littleCoder DB specifies only one byte in memory as the string's starting address. assume its offest 0200H. the number of characters in the string is what tells the assembler how many bytes of storage to set aside for that string which in this case is ' example of define byte string ' is more than one byte. but it starts at 0200H.

    so any time you call the bookmark littleCoder, you are telling the assembler to put the address of memory offset (adress) 0200H into register AX. [ MOV AX, littleCoder ].

    Machine instructions are as the name implies, instructions to the CPU. Directives by contrast are only instructions to the assembler. When assembler encounters directive such as one in above example, its like a sign post telling the assembler set aside one byte of the memory right here for the value that follows .

    Hope this helps.



  • yellowfieroyellowfiero Member Posts: 1
    : The label directive is used when you want that some area of the data segment is used as a variable. Using this code:
    :
    : .model small
    : .code
    :
    : msg label byte
    : db 'Test of Message',13,10,'$'
    :
    : start:
    : mov ah,9
    : mov dx,offset msg
    : push cs
    : pop ds
    : int 21h
    : mov ah,4ch
    : int 21h
    : end start
    :
    : Will print the Test of Message on the display. I dont know why use this instead of:
    :
    : msg db 'Test of Message',13,10,'$'
    :
    : But it's the same thing.
    :
    : Note: This code is for TASM.
    :
    : Davi Medrade
    : Brazil
    :
    :
    I agree with Davi on using the 'label' before the db in the define data area of the program, however, as will all of the rest of the posts on this matter, they seem to all be linked to DOS assembly language programming. From an embedded programmer (like myself), small embedded applications can be written more efficiently using the LABEL directive for things such as definition of the stack.



    For instance, to define a 32 word stack:

    4 0100_00_00_00_00_00_00__stck dw 32 dup (?)
    5 ________________________dmy label byte
    6
    7 0140_BC_40_01___________mov sp, offset dmy


    The label directive allows you to create a pointer without reserving memory. So for the stack, to init @ the top of the stack, it is really a handy tool. For the mentioned array however, it is not necessary, since you can embed the label in front of the db or dw. This cannot be done with the stack example shown, because then the label would be pointing to the bottom of the stack, not top. Can it be done differently? Sure, here's a couple of ways:
    --------
    1)
    4 0100_00_00_00_00_00_00_____stck dw 32 dup (?)
    5 0140_00____________________dmy db ?
    6
    7 0141_BC_40_01______________mov sp, offset dmy

    --------
    2)
    4 0100_00_00_00_00_00_00_____stck dw 32 dup (?)
    5
    6
    7 0140_BC_40_01______________mov sp, offset stck + 32 * 2


    Now I hope that the Label directive's usefulness can be seen.

    Note: underscores inserted for spaces.

  • BitdogBitdog Member Posts: 528
    : define a 32 word stack:
    :
    : 4 0100_00_00_00_00_00_00__stck dw 32 dup (?)
    : 5 ________________________dmy label byte
    : 6
    : 7 0140_BC_40_01___________mov sp, offset dmy
    :
    :
    : The label directive allows you to create a pointer without reserving memory.



    Thanks, YellowFiero, I'll try some practice code on it too.
    (mines a gold 87 SE needs a shifter cable)
    Here's a strange asm:


    ; nasm -f bin this.asm -o this.com
    BITS 16
    ORG 100h

    CALL PRNT
    DB "Hello world!",13,10,195

    PRNT:
    MOV AH,2
    POP SI
    LABEL:
    LODSB
    MOV DL,AL
    INT 21h
    CMP AL,10
    JNZ LABEL
    JMP SI

  • davimedradedavimedrade Member Posts: 105
    :
    : Now I'm curious. Does LABEL BYTE
    : mean a short jump/call ?
    : what does the BYTE mean ?
    : What part of my previous rambling was incorrect too ?
    : Thankx in advance, Mr. Medrade.
    :
    : Sincerely
    : ...... Bitdog
    : (little bit dog, little bit human)
    :
    :

    Since the LABEL is used as a variable, you should not use a CALL or JMP to a LABEL. But you can use the LABEL in the following code:

    MSG LABEL BYTE
    DB 'Test.'

    MOV AX,OFFSET MSG

    The BYTE means that you should access the variable in Byte portions.

    MSG LABEL BYTE
    DB 'Test.'
    MOV BX,OFFSET MSG
    MOV [BX],1

    Will put a BYTE with value 1 in the first memory address after the LABEL (changing the T of Test). But:

    MSG LABEL WORD
    DB 'Test.'
    MOV BX,OFFSET MSG
    MOV [BX],1

    Will put a WORD with a value 1 in the first and second memory addresses after the LABEL (changing the T and the e of test).

    Available and useful types are:
    BYTE, WORD, DWORD, QWORD
    1B 2B 4B-2W 8B-4W

    Davi Medrade
    Brazil

    PS: Plz. Call me Davi, and not Mr. Medrade, ok? I am only 14 yr old.

  • little_coderlittle_coder Member Posts: 29
    : Since the LABEL is used as a variable, you should not use a CALL or JMP to a LABEL. But you can use the LABEL in the following code:
    : [code]
    : MSG LABEL BYTE
    : DB 'Test.'
    :
    : MOV AX,OFFSET MSG
    : [/code]
    : The BYTE means that you should access the variable in Byte portions.
    :


    - I wonder, then. What is the difference if we simply write this:

    [code]
    MSG:
    DB 'Test.'

    MOV AX, MSG

    [/code]

    I'm still curious why someone invented this LABEL directive...

«1
Sign In or Register to comment.