高手帮忙改一下下面的汇编程序使其能执行,然后在此基础上将题目改为以8进制形式输出,写出程序!!!
TITLE从键盘输入两位16进制数,输出其2进制数形式datasegmenttt1db0hdataendsstacksegmentparastackdb100dup(?)...
TITLE 从键盘输入两位16进制数,输出其2进制数形式
data segment
tt1 db 0h
data ends
stack segment para stack
db 100 dup(?)
stack ends
code segment
assume cs:code,ds:data,es:data,ss:stack
sub1 proc far
start: push ds
mov ax,0
push ax
mov ax,data
mov ds,ax
mov es,ax
call sub4
mov cl,4
shl al,cl
mov tt1,al
call sub4
add al,tt1
mov cx,8
next: rol al,1
mov tt1,al
and al,00000001
call sub2
mov al,ttl
loop next
ret
SUB1 ENDP
sub4 proc
mov ah,1
int 21h
cmp al,"9"
ja qq1
sub al,30h
jmp qq2
qq1: sub al,57h
qq2: ret
sub4 endp
SUB2 PROC
cmp al,9
ja g1
add al,"0"
jmp g2
g1: add al,37h
g2: mov dl,al
mov ah,2
int 21h
RET
SUB2 ENDP
code ends
end start 展开
data segment
tt1 db 0h
data ends
stack segment para stack
db 100 dup(?)
stack ends
code segment
assume cs:code,ds:data,es:data,ss:stack
sub1 proc far
start: push ds
mov ax,0
push ax
mov ax,data
mov ds,ax
mov es,ax
call sub4
mov cl,4
shl al,cl
mov tt1,al
call sub4
add al,tt1
mov cx,8
next: rol al,1
mov tt1,al
and al,00000001
call sub2
mov al,ttl
loop next
ret
SUB1 ENDP
sub4 proc
mov ah,1
int 21h
cmp al,"9"
ja qq1
sub al,30h
jmp qq2
qq1: sub al,57h
qq2: ret
sub4 endp
SUB2 PROC
cmp al,9
ja g1
add al,"0"
jmp g2
g1: add al,37h
g2: mov dl,al
mov ah,2
int 21h
RET
SUB2 ENDP
code ends
end start 展开
1个回答
展开全部
TITLE 从键盘输入两位16进制数,输出其2进制数形式
;==============================================
DISP_STR MACRO X ;宏定义.
MOV DX, OFFSET X
MOV AH, 9
INT 21H
ENDM
;----------------------------------------------
DATA SEGMENT ;数据段.
MSG1 DB 13, 10, 'Please Input : $'
MSG3 DB 13, 10, 'The BIN is : $'
x DB ? ;存放新输入数据.
DATA ENDS
;----------------------------------------------
CODE SEGMENT ;代码段.
ASSUME CS: CODE, DS: DATA
START:
MOV AX, DATA
MOV DS, AX
;--------------------------------
DISP_STR MSG1 ;宏调用,提示 Please Input :
;--------------------------------
IN_LOOP:
MOV x, 0 ;数据清零.
MOV CH, 2
_INX:
MOV AH, 1 ;输入字符.
INT 21H
;--------------------------------
CMP AL, '0'
JB _IN_END ;小于'0',不是数字.
CMP AL, 3AH
JB SUB_30H ;'0'~'9'.
CMP AL, 'A'
JB _IN_END ;小于'A',不是数字.
CMP AL, 'G'
JB SUB_37H ;'A'~'F'.
JNB _IN_END ;全部数字结束.
;--------------------------------
SUB_37H:
SUB AL, 7
SUB_30H:
SUB AL, '0'
MOV CL, AL
MOV AL, x
MOV BL, 16 ;老数据乘以16
MUL BL
ADD AL, CL ;加上新数据.
MOV x, AL ;保存.
DEC CH
JNZ _INX ;继续输入.
;--------------------------------
_IN_END:
DISP_STR MSG3 ;宏调用,提示 The BIN is :
MOV AL, x
MOV CX, 8 ;显示8位数.
DDDD:
MOV DL, '0' ;先计划显示0
TEST AL, 80H ;测试最高位.
JZ DDD1
INC DL ;非0就显示1
DDD1:
PUSH AX
MOV AH, 2 ;显示DL中的ASCII码.
INT 21H
POP AX
SHL AL, 1 ;左移.
LOOP DDDD ;CX-1,非零转移.
;--------------------------------
MOV AH, 4CH
INT 21H
;--------------------------------
CODE ENDS
END START
;==============================================
;==============================================
DISP_STR MACRO X ;宏定义.
MOV DX, OFFSET X
MOV AH, 9
INT 21H
ENDM
;----------------------------------------------
DATA SEGMENT ;数据段.
MSG1 DB 13, 10, 'Please Input : $'
MSG3 DB 13, 10, 'The BIN is : $'
x DB ? ;存放新输入数据.
DATA ENDS
;----------------------------------------------
CODE SEGMENT ;代码段.
ASSUME CS: CODE, DS: DATA
START:
MOV AX, DATA
MOV DS, AX
;--------------------------------
DISP_STR MSG1 ;宏调用,提示 Please Input :
;--------------------------------
IN_LOOP:
MOV x, 0 ;数据清零.
MOV CH, 2
_INX:
MOV AH, 1 ;输入字符.
INT 21H
;--------------------------------
CMP AL, '0'
JB _IN_END ;小于'0',不是数字.
CMP AL, 3AH
JB SUB_30H ;'0'~'9'.
CMP AL, 'A'
JB _IN_END ;小于'A',不是数字.
CMP AL, 'G'
JB SUB_37H ;'A'~'F'.
JNB _IN_END ;全部数字结束.
;--------------------------------
SUB_37H:
SUB AL, 7
SUB_30H:
SUB AL, '0'
MOV CL, AL
MOV AL, x
MOV BL, 16 ;老数据乘以16
MUL BL
ADD AL, CL ;加上新数据.
MOV x, AL ;保存.
DEC CH
JNZ _INX ;继续输入.
;--------------------------------
_IN_END:
DISP_STR MSG3 ;宏调用,提示 The BIN is :
MOV AL, x
MOV CX, 8 ;显示8位数.
DDDD:
MOV DL, '0' ;先计划显示0
TEST AL, 80H ;测试最高位.
JZ DDD1
INC DL ;非0就显示1
DDD1:
PUSH AX
MOV AH, 2 ;显示DL中的ASCII码.
INT 21H
POP AX
SHL AL, 1 ;左移.
LOOP DDDD ;CX-1,非零转移.
;--------------------------------
MOV AH, 4CH
INT 21H
;--------------------------------
CODE ENDS
END START
;==============================================
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询