当前位置: 代码迷 >> 汇编语言 >> 汇编将有符号数转向16进制数并显示
  详细解决方案

汇编将有符号数转向16进制数并显示

热度:5502   发布时间:2013-02-26 00:00:00.0
汇编将有符号数转为16进制数并显示
.386
DATA SEGMENT USE16
BUFA DB 50
  DB 0
  DB 50 DUP(0)
  CRLF DB 0DH,0AH,'$'
BUFB DB 50 DUP(0)
CC DW 0
FLAG DB 0
DATA ENDS

STACK SEGMENT USE16 STACK
  DB 200 DUP(0)
STACK ENDS

CODE SEGMENT USE16
  ASSUME CS:CODE,DS:DATA,SS:STACK
START:MOV AX,DATA
  MOV DS,AX
  LEA DX,BUFA
  MOV AH,10
  INT 21H
  LEA DX,CRLF
  MOV AH,9
  INT 21H
  MOV BL,BUFA+1
  MOV BH,0
  LEA SI,BUFA+2
  MOV EAX,0
  CALL SIGN
J1: MOV CL,[SI]
  SUB CL,30H
  MOVZX ECX,CL
  ADD EAX,ECX
  IMUL EAX,10
  INC SI
  DEC BX
  CMP BX,1
  MOV ECX,0
  JNE J1
  MOV CL,[SI]
  SUB CL,30H
  MOVZX ECX,CL
  ADD EAX,ECX
  MOV ECX,0
  MOV EBX,16
  CMP FLAG,1
  JNE J2
  NEG EAX
J2: XOR EDX,EDX
  DIV EBX
  PUSH DX
  INC CX
  OR EAX,EAX
  JNZ J2
  MOV CC,CX
  LEA DI,BUFB
J3: POP AX
  CMP AL,10
  JB L1
  ADD AL,7
L1: ADD AL,30H
  MOV [DI],AL
  INC DI
  LOOP J3
  INC DI
  MOV BYTE PTR [DI],'$'
  LEA DX,BUFB
  MOV AH,9
  INT 21H
  MOV AH,4CH
  INT 21H
SIGN PROC
  MOV CX,BX
  PUSH BX
  MOV BL,[SI]
  CMP BL,'+'
  JE F1
  CMP BL,'-'
  JNE F2
  MOV FLAG,1
  DEC CX
  INC SI
  JMP F3
F1: MOV FLAG,0
  DEC CX
  INC SI
  JMP F3
F2: MOV FLAG,0  
  END START
  JMP F3
F3: POP BX 
  CMP BX,CX
  JNE F4
  RET
F4: MOV BX,CX
  RET
SIGN ENDP
CODE ENDS 
  END START 、


编译显示 unmatched block nesting 如何解决。

小白拜谢了。

------解决方案--------------------------------------------------------
.386
DATA SEGMENT USE16
BUFA DB 50
DB 0
DB 50 DUP(0)
CRLF DB 0DH,0AH,'$'
BUFB DB 50 DUP(0)
CC DW 0
FLAG DB 0
DATA ENDS

STACK SEGMENT USE16 STACK
DB 200 DUP(0)
STACK ENDS

CODE SEGMENT USE16
ASSUME CS:CODE,DS:DATA,SS:STACK
START:MOV AX,DATA
MOV DS,AX
LEA DX,BUFA
MOV AH,10
INT 21H
LEA DX,CRLF
MOV AH,9
INT 21H
MOV BL,BUFA+1
MOV BH,0
LEA SI,BUFA+2
MOV EAX,0
CALL SIGN
J1: MOV CL,[SI]
SUB CL,30H
MOVZX ECX,CL
ADD EAX,ECX
IMUL EAX,10
INC SI
DEC BX
CMP BX,1
MOV ECX,0
JNE J1
MOV CL,[SI]
SUB CL,30H
MOVZX ECX,CL
ADD EAX,ECX
MOV ECX,0
MOV EBX,16
CMP FLAG,1
JNE J2
NEG EAX
J2: XOR EDX,EDX
DIV EBX
PUSH DX
INC CX
OR EAX,EAX
JNZ J2
MOV CC,CX
LEA DI,BUFB
J3: POP AX
CMP AL,10
JB L1
ADD AL,7
L1: ADD AL,30H
MOV [DI],AL
INC DI
LOOP J3
INC DI
MOV BYTE PTR [DI],'$'
LEA DX,BUFB
MOV AH,9
INT 21H
MOV AH,4CH
INT 21H
SIGN PROC
MOV CX,BX
PUSH BX
MOV BL,[SI]
CMP BL,'+'
JE F1
CMP BL,'-'
JNE F2
MOV FLAG,1
DEC CX
INC SI
JMP F3
F1: MOV FLAG,0
DEC CX
  相关解决方案