-1

This is my code (I know this wrong):

org 100h

sert dw 1 
 
mov si, 1
shl si, 1
lea ax,[si]   
 
jmp ax

1:
PRINTN "Number 1"
jmp end

2:
PRINTN "Number 2"
jmp end

3:
PRINTN "Number 3"
jmp end

4:
PRINTN "Number 4"
jmp end

end:


mov ah, 0 
int 16h
ret 
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
  • 1
    One other observation not related to your question. Don't place you data in the code path like you did with `sert dw 1` . The processor will attempt to execute that value `0001h` as code. Place the data somewhere that the processor won't execute it (like after the code) – Michael Petch Nov 16 '20 at 20:03

1 Answers1

2

Try something like this:

        mov si, 1
        shl si, 1        ; adjust index for table entry size
        jmp [table+si]   ; branch to the destination found in the table

l1:     PRINTN "Number 1"
        jmp end

l2:     PRINTN "Number 2"
        jmp end

l3:     PRINTN "Number 3"
        jmp end

l4:     PRINTN "Number 4"
        jmp end

end:    ...

        ; jump table
        ; place this outside of your control flow
table   dw l1, l2, l3, l4
fuz
  • 88,405
  • 25
  • 200
  • 352
  • 2
    Aligning the jump table on a word boundary is useful. In NASM source you'd have to put "align 2" into a line prior to the "table" label. – ecm Nov 16 '20 at 11:54