TASM中的“近跳或调用不同的CS”错误

时间:2016-04-17 15:42:53

标签: assembly binary-search dos tasm x86-16

我一直在尝试使用汇编来理解二进制搜索算法,但每当我尝试汇编代码时都会收到错误Near jump or call to different CS。错误发生在我使用JMP或其变体指令之一的行。我正在使用TASM,我的代码是:

 DATA SEGMENT
 ARR DW 0000H,1111H,2222H,3333H,4444H,5555H,6666H,7777H,8888H,9999H
 LEN DW ($-ARR)/2
 KEY EQU 7777H
 MSG1 DB "KEY IS FOUND AT "
 RES DB "  POSITION",13,10," $"
 MSG2 DB "KEY NOT FOUND!!!.$"
 DATA ENDS
CODE SEGMENT 
ASSUME DS:DATA CS:CODE
START:
  MOV AX,DATA
  MOV DS,AX
  MOV BX,00
  MOV DX,LEN
  MOV CX,KEY
AGAIN: CMP BX,DX
   JA FAIL
   MOV AX,BX
   ADD AX,DX
   SHR AX,1
   MOV SI,AX
   ADD SI,SI
   CMP CX,ARR[SI]
   JAE BIG
   DEC AX
   MOV DX,AX
   JMP AGAIN
  BIG:JE SUCCESS
   INC AX
   MOV BX,AX
   JMP AGAIN
  SUCCESS: ADD AL,01
   ADD AL,'0'
   MOV RES,AL
   LEA DX,MSG1
   JMP DISP
  FAIL: LEA DX,MSG2
  DISP: MOV AH,09H
   INT 21H
   MOV AH,4CH
   INT 21H     
  CODE ENDS
  END START

1 个答案:

答案 0 :(得分:2)

CODE SEGMENT中,您错过了将段声明与ASSUME分开的昏迷(第10行)。将其更改为:

ASSUME DS:DATA, CS:CODE