Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6822241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:38:22+00:00 2026-05-26T21:38:22+00:00

As part of our assignment we are supposed to do various functions with matrices.

  • 0

As part of our assignment we are supposed to do various functions with matrices. For the menu, we are assigned to use a “case table” (which is implemented as a 2-D array with each row containing only a letter constant and its corresponding function)

I really cannot make sense of the notes, and the book is zero help (it doesn’t mention them at all)

    .data
CaseTable BYTE 'A'  ; lookup value
    DWORD Process_A ; address of procedure
    EntrySize = ($ - CaseTable)
    BYTE 'B'
    DWORD Process_B
    BYTE 'C'
    DWORD Process_C
    BYTE 'D'
    DWORD Process_D

NumberOfEntries = ($ - CaseTable) / EntrySize
….
segment .text
...
    mov ebx, CaseTable  ; point EBX to the table
    mov ecx,NumberOfEntries ; loop counter

L1: cmp al,[ebx]    ; match found?
    jne L2  ; no: continue
    call PTR [ebx + 1]  ; yes: call the procedure
    jmp L3  ; and exit the loop
L2: add ebx,EntrySize   ; point to next entry
    loop L1 ; repeat until ECX = 0

L3:

Can someone help me make sense of this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:38:23+00:00Added an answer on May 26, 2026 at 9:38 pm

    The idea is trivial. If you don’t know enough assembly language, try understanding the following equivalent C code (I took the liberty of defining Process_*() as printing distinct letters and throwing in main()):

    #include <stdio.h>
    
    void Process_A(void)
    {
      printf("A\n");
    }
    
    void Process_B(void)
    {
      printf("B\n");
    }
    
    void Process_C(void)
    {
      printf("C\n");
    }
    
    void Process_D(void)
    {
      printf("D\n");
    }
    
    typedef struct
    {
      char Char;
      void (*Subroutine)(void);
    } CaseTableEntry;
    
    CaseTableEntry CaseTable[] =
    {
      { 'A', &Process_A }, // equivalent to "BYTE 'A'" + "DWORD Process_A"
      { 'B', &Process_B },
      { 'C', &Process_C },
      { 'D', &Process_D }
    };
    
    void Process(char Char)
    {
      const size_t NumberOfEntries = sizeof(CaseTable) / sizeof(CaseTableEntry);
      CaseTableEntry* entry = &CaseTable[0]; // equiv to "mov ebx, CaseTable"
      size_t count = NumberOfEntries; // equiv to "mov ecx, NumberOfEntries"
    
      do
      {
        // "L1:" would be here
        if (entry->Char == Char) // equiv to "cmp al,[ebx]" + "jne L2"
        {
          entry->Subroutine(); // equiv to "call PTR [ebx + 1]"
          break; // equiv to "jmp L3"
        }
        // "L2:" would be here
        entry++; // equiv to "add ebx, EntrySize"
      } while (--count > 0); // equiv to "loop L1"
      // "L3:" would be here
    }
    
    int main(void)
    {
      Process('A');
      Process('B');
      Process('X');
      Process('C');
      Process('D');
      return 0;
    }
    

    Output:

    A
    B
    C
    D
    

    The only problems here can be things like $ and mov ebx, CaseTable.

    $ evaluates to the assembly position at the beginning of the line containing the expression; so you can code an infinite loop using JMP $.

    Hence EntrySize = ($ - CaseTable) calculates the size of the first entry of the table and likewise NumberOfEntries = ($ - CaseTable) / EntrySize first calculates the entire table size and then divides it by the size of one entry giving you the number of the table entries.

    Unlike in other assemblers (e.g. MASM and TASM), in NASM mov ebx, CaseTable means loading into ebx the address of the object named CaseTable. In other assemblers this can mean reading into ebx the first 4 bytes from the object named CaseTable.
    Similarly, DWORD Process_A defines a DWORD containing the address of the object named Process_A.
    In other assemblers the equivalents may need to be written as mov ebx, OFFSET CaseTable and DWORD OFFSET Process_A.

    For the rest, please consult your book, the official NASM documentation and Intel’s / AMD’s x86 CPU manuals. Do your homework, basically. If anything isn’t clear, come and ask specific questions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Part of our core product is a website CMS which makes use of various
Part of our product is an IE plugin (BHO), which is running happily in
At our company we use clickonce deployment for the client part of our client/server
We use tags in git as part of our deployment process. From time to
This is part of an assignment. Everything that's supposed to work, already works, but
We use ant as part of our build system for copying a load of
I've been working on our intro scripting assignment, and am having issues calling functions
We have some devs on Android part of our application who actively use prefixing
We're working on a group assignment. Part of the program is for the use
Part of our java application needs to run javascript that is written by non-developers.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.