跳台 - 组装8086

时间:2014-05-10 20:45:37

标签: c assembly branch jump-table

我试图像这样制作开关案例:

 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;
 }

在具有分支表/跳转表的程序集8086中:

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

PRINTN就像是C中的printf。

我的代码不起作用,我不知道为什么......

我做错了什么?

1 个答案:

答案 0 :(得分:1)

使用表格和存储某些字符串的示例:

表本身的地址= OFFSET JTab

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

一些字符串的地址,OFFSET为T1,T2,T3,T4,长度为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)