Howdy, Stranger!

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

Categories

Procedure address table

edspitedspit Member Posts: 12
I need a table containing ten 16-bit procedure offsets. A program that displays a menu from 1 to 10. Use the number to locate the address of the procedure. Call the procedure using indirect addressing. Return to menu and hit escape to exit.

Comments

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : I need a table containing ten 16-bit procedure offsets. A program that displays a menu from 1 to 10. Use the number to locate the address of the procedure. Call the procedure using indirect addressing. Return to menu and hit escape to exit.
    :
    [blue]Just a tip:[/blue][code]
    .MODEL TINY

    .DATA
    tblProcs Dw Proc1, Proc2, Proc3

    .CODE
    Proc1 Proc
    ret
    Proc1 EndP

    Proc2 Proc
    ret
    Proc2 EndP

    Proc3 Proc
    ret
    Proc3 EndP

    ; INPUT: Index in range [0..2] in AX
    CallMe Proc
    mov bx, offset [tblProcs]
    mov si, ax
    shl si, 1 ; Because, 2 WORDs will be 4 bytes, etc.
    call word ptr [bx+si]

    ret
    CallMe EndP
    End
    [/code]
  • blipblip Member Posts: 756
    [b][red]This message was edited by Moderator at 2002-10-4 13:42:0[/red][/b][hr]
    I hope you don't mind if I use 32-bit addressing, it's just more convenient:
    [code]
    ;NASM code:

    Menu:
    ;Do your own display here, I don't know how you want it!

    GetKey:
    xor ah,ah
    int 16h
    cmp al,1Bh ;ESC ASCII code.
    jz Exit
    cmp al,"0" ;I hope you don't mind if I use 0-9 instead....
    jb GetKey
    cmp al,"9"
    ja GetKey
    movzx esi,al
    call word [CallTable-"0"+esi*2] ;DS had better equal SEG CallTable!
    jmp Menu

    Exit:
    int 20h

    ;Set up your own procedures here by the names of the ones in the call
    ;table, but you can also change the names in the call table if you want to.

    CallTable dw Proc0, Proc1, Proc2, Proc3, Proc4
    dw Proc5, Proc6, Proc7, Proc8, Proc9
    [/code]


Sign In or Register to comment.