DATA SEGMENT;代码如下,请高手指教.小生不胜感激....
CR db 0ah,'$'
SSP db 20h,'$'
string1 db 'plese input the number:$'
string2 db 'the number is(H):$'
string3 db 'the number is(B):$'
data1 db 5h,0h,5h dup(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
lea dx,string1
mov ah,9h
int 21h;显示字符串string1
lea dx,data1
mov ah,0ah
int 21h;键盘输入四位十六进制数
mov dx,offset CR
mov ah,9
int 21h ;输出回车换行符
lea dx,string2
mov ah,9h
int 21h;显示字符串string2
mov bx,offset data1
mov si,bx
xor cx,cx
mov cx,04h
next:mov al,[si+2]
mov dl,al
mov ah,2h
int 21h
inc si
loop next;显示输出四位十六进制
mov dx,offset SSP
mov ah,9h
int 21h;输出空格符
lea dx,string3
mov ah,9h
int 21h;显示字符串string1
mov cl,4h
xor bx,bx
next3:mov al,[si+2]
add bx,ax
shl bx,cl
mov al,[si+3]
add bx,ax
shl bx,cl
mov al,[si+4]
add bx,ax
shl bx,cl
mov al,[si+5]
add bx,ax;把SI指向的数存入BX中,此时BX表示四位十六进制数
mov cx,10h;循环次数16
next2:shl bx,1;左移一位
jnc dis0;若CF为0,转到dis0
mov dl,31h;CF=1,显示“1”
jmp disp
dis0:mov dl,30h;显示“0”
disp:mov ah,2h
int 21h
loop next2;循环16次
mov ah,4ch
int 21h
CODE ENDS
END START
汇编输入四位16进制数转成二进制输出
答案:2 悬赏:10 手机版
解决时间 2021-05-10 05:35
- 提问者网友:愿为果
- 2021-05-09 17:31
最佳答案
- 五星知识达人网友:廢物販賣機
- 2021-05-09 19:05
DATA SEGMENT;能判断输入数据,并大小写通用..,,,都提交不上去,真晕晕晕
CR db 0ah,'$'
SSP db 20h,'$'
er db 'error$'
string1 db 'please input four nums:$'
string2 db 'num(H):$'
string3 db 'num(B):$'
data1 db 5h,0h,5h dup(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
lea dx,string1
mov ah,9h
int 21h;显示字符串string1
lea dx,data1
mov si,dx
mov ah,0ah
int 21h;键盘输入四位十六进制数
mov dx,offset CR
mov ah,9
int 21h ;输出回车换行符
lea dx,string2
mov ah,9h
int 21h;显示字符串string2
mov cl,04h
next:mov al,[si+2]
mov dl,al
mov ah,2h
int 21h
inc si
loop next;显示输出四位十六进制
mov dx,offset SSP
mov ah,09h
int 21h;输出空格符
lea dx,string3
mov ah,9h
int 21h;显示字符串string1
mov cl,04h
xor bx,bx
xor ax,ax
mov di,04h
next3:mov al,[si-2]
dec di
inc si
cmp al,30h
jc error
cmp al,3ah
jc num1
cmp al,41h
jc error
cmp al,47h
jc num2
cmp al,61h
jc error
cmp al,67h
jc num3
cmp al,7e
jc error
num1: sub al,30h
jmp xx
num2:sub al,37h
jmp xx
num3:sub al,57h
xx: add bx,ax
cmp di,0h
jz next4
shl bx,cl
next4: cmp di,0h
jnz next3
xor cx,cx
clc
mov cx,10h;循环次数16
next1:shl bx,1;左移一位
jc dis1;若CF=1,转到dis1
mov dl,'0';CF=0,显示“0”
jmp disp
dis1:mov dl,'1';显示“1”
disp:mov ah,2
int 21h
loop next1
jmp xxx
error:lea dx,er
mov ah,9h
int 21h;显示字符串er2
xxx: mov ah,4ch
int 21h
CODE ENDS
END START
CR db 0ah,'$'
SSP db 20h,'$'
er db 'error$'
string1 db 'please input four nums:$'
string2 db 'num(H):$'
string3 db 'num(B):$'
data1 db 5h,0h,5h dup(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
lea dx,string1
mov ah,9h
int 21h;显示字符串string1
lea dx,data1
mov si,dx
mov ah,0ah
int 21h;键盘输入四位十六进制数
mov dx,offset CR
mov ah,9
int 21h ;输出回车换行符
lea dx,string2
mov ah,9h
int 21h;显示字符串string2
mov cl,04h
next:mov al,[si+2]
mov dl,al
mov ah,2h
int 21h
inc si
loop next;显示输出四位十六进制
mov dx,offset SSP
mov ah,09h
int 21h;输出空格符
lea dx,string3
mov ah,9h
int 21h;显示字符串string1
mov cl,04h
xor bx,bx
xor ax,ax
mov di,04h
next3:mov al,[si-2]
dec di
inc si
cmp al,30h
jc error
cmp al,3ah
jc num1
cmp al,41h
jc error
cmp al,47h
jc num2
cmp al,61h
jc error
cmp al,67h
jc num3
cmp al,7e
jc error
num1: sub al,30h
jmp xx
num2:sub al,37h
jmp xx
num3:sub al,57h
xx: add bx,ax
cmp di,0h
jz next4
shl bx,cl
next4: cmp di,0h
jnz next3
xor cx,cx
clc
mov cx,10h;循环次数16
next1:shl bx,1;左移一位
jc dis1;若CF=1,转到dis1
mov dl,'0';CF=0,显示“0”
jmp disp
dis1:mov dl,'1';显示“1”
disp:mov ah,2
int 21h
loop next1
jmp xxx
error:lea dx,er
mov ah,9h
int 21h;显示字符串er2
xxx: mov ah,4ch
int 21h
CODE ENDS
END START
全部回答
- 1楼网友:孤老序
- 2021-05-09 19:20
DATA SEGMENT;代码如下,请高手指教.小生不胜感激....
CR db 0dh,0ah,'$'
SSP db 20h,'$'
string1 db 'plese input the number:$'
string2 db 'the number is(H):$'
string3 db 'the number is(B):$'
data1 dw 0
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
lea dx,string1
mov ah,9h
int 21h;显示字符串string1
lea dx,data1
mov ah,0ah
int 21h;键盘输入四位十六进制数
mov dx,offset CR
mov ah,9
int 21h ;输出回车换行符
lea dx,string2
mov ah,9h
int 21h;显示字符串string2
xor bx, bx
mov dx, 4
mov cx, dx
next:
xchg cx, dx
shl bx, cl
xchg cx, dx
mov ah, 1
int 21h
cmp al, '9'
ja alpha
sub al, '0'
jmp cnt
alpha:
sub al, 'a'
add al, 10
cnt:
add bl, al
loop next
mov ah, 9
lea dx, string3
int 21h
mov cx, 16
next2:
rol bx, 1
test bx, 1
jnz ones
mov dl, '0'
jmp output
ones:
mov dl, '1'
output:
mov ah, 2
int 21h
loop next2
mov ah,4ch
int 21h
CODE ENDS
END START
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯