-5

I've tried to make switch case like this:

 switch (si)
{
 case 1:
   printf( “Number One” );
   break;

case 2:
   printf( “Number Two” );
   break;

 case 3:
   printf( “Number Three” );
   break;

 case 4:
  printf( “Number Four” );
  break;
 }

In assembly 8086 with branch table/jump table:

enter code here
org 100h 

mov si,1 
mov bx,10
sub si,1
add si,si
mov bx,[bx+si]
jmp bx 

address:
dw 14 Case1
dw 17 Case2
dw 21 Case3
dw 24 Case4 

Case1: PRINTN "Number One"
jmp End

Case2: PRINTN "Number Two"   
jmp End

Case3: PRINTN "Number Three"
jmp End

Case4: PRINTN "Number Four"

End:
mov ah, 0
int 16h
ret

The PRINTN is like printf in C.

My code doesn't work and I don't know why...

What I'm doing wrong?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user3621372
  • 11
  • 1
  • 2
  • 1
    I don't understand the magic numbers, 10,14,17,21,24? – Martin James May 10 '14 at 21:21
  • 1
    *Can you plz fix my bugs?* - If you've found specific bugs and have tried to fix them, we can help. Other than that, SO is not a code-debugging service. – Jamal May 10 '14 at 23:11

1 Answers1

1

Example for to use a table and for to store some strings:

Address of the table itself = OFFSET JTab

JTab dw OFFSET Case1, OFFSET Case2, OFFSET Case3, OFFSET Case4

Addresses of some Strings with OFFSET of T1, T2, T3, T4 with lenght in len1, len2, ...

T1 db "Number One"
len1 = ($-T1)

T2 db "Number Two"
len2 = ($-T2)

T3 db "Number Three"
len3 = ($-T3)

T4 db "Number Four"
len4 = ($-T4)