In NASM
assembler, it's possible to declare local label using .
prefix.
- So, what is the address of local label (and label in all assemblers generally)? Is it relative or absolute, or it depends on use?
I'm asking because there are features that confuse me. This is an example code:
ORG 0x400000 ;origin of address for labels
start: ;address here should be 0x400000
..... ;some code here
.loop ;local label
..... ;some code here
jmp short .loop ;<------- address is not taken as absolute
jmp short start
If I take some normal label (like start
) for referencing and I use it with lea
instruction, address is calculated as normal absolute address with respect to origin.
- But if I take label and I use it with
short
(as on the last line), what is happening? Is the offset for jump calculated from absolute address?
I'm asking all this because I have local labels in my code (.LNXYZ
, randomly generated), and I need to make list of addresses (from that labels) that will have 4-byte elements containing absolute address for jumps. Is such thing possible, or I have to use normal labels? Is there any directive for it?
bits 32
at the top of this. Your origin seems a little high for 16-bit code (which is what Nasm will produce by default.jmp label
uses relative addressing mode - the actual code emitted will bejmp distance_to_label
. Shouldn't matter if the label is "local" or not. For an absolute jump, you'll have to domov eax, label
and thenjmp eax
. You shouldn't need to codeshort
- Nasm should give you ashort
jump if it'll fit, and anear
jump if it won't. I'm not sure I get the part about "randomly generated" labels... – Frank Kotler