Jump to specific line in x86 assembly language

12,142

You can just put a label at that line. Depending on your assembly language dialect, you might be be able to use a numeric local label, or you might need to use symbolic labels. A possible example follows. I have only NASM here to test, so I'm not really sure this example will map well to MASM, but you should get the idea:

start:
    jmp .line3
    mov ax, 0
.line3:
    mov bx, 0
    mov ah, 1

NASM uses a leading . to identify local labels.

Share:
12,142
Anderson Green
Author by

Anderson Green

I write source-to-source compilers in JavaScript using Peggyjs. I also write compilers in Prolog. For reference, I also have a list of source-to-source compilers on GitHub.

Updated on June 18, 2022

Comments

  • Anderson Green
    Anderson Green almost 2 years

    In x86 assembly language, is it possible to specify a jump to a specific line number? Here, I'm trying to use the jmp instruction to the line number 3. (I don't yet know of a way to pass a label as a parameter to a function, so I'm trying to use a line number instead of a label in this case.)

    .686p
    .model flat,stdcall
    .stack 2048
    .data
    
    ExitProcess proto, exitcode:dword
    .code
    
    start:
    
    jmp 3; this produces the error shown below
    
    mov ax, 0
    mov bx, 0
    mov ah, 1
    
    invoke  ExitProcess, 0
    end start
    

    The code above produces the error 1>p4.asm(11): error A2076: jump destination must specify a label.