1,从键盘输入一个4位的十六进制数,统计该数所对应的二进制数中所包含"1"的个数,并输出.(汇编语言)
答案:3 悬赏:10 手机版
解决时间 2021-03-03 00:01
- 提问者网友:你挡着我发光了
- 2021-03-02 07:55
求高手写8088汇编语言源代码
最佳答案
- 五星知识达人网友:孤老序
- 2021-03-02 08:34
最近怎么很多人问这个
只能识别大写字母 A-F
ASSUME CS:CODE,DS:DATA,SS:STACK
DATA SEGMENT
TEMP DW ?
MSG1 DB 13,10,"PLEASE INPUT A HEX NUMBER : $"
MSG2 DB 10,13,"THE HEX NUMBER HAVE $"
ANS DB " 1 $"
ERR DB 'BKADBKS'
H16 DW 16
DATA ENDS
STACK SEGMENT
DB 128 DUP (0)
TOS DB '$'
STACK ENDS
CODE SEGMENT
; 十六进制转换十进制
CONVERT PROC
MOV BL,10
MOV CX,0
L:
DIV BL
ADD AH,30H
INC CX
PUSH AX
MOV AH,0
CMP AL,0
JNZ L
O:
POP DX
MOV DL,DH
MOV DH,0
MOV AH,2
INT 21H
LOOP O
RET
CONVERT ENDP
;统计AX中1的个数,结果在BX中,用循环位移实现
COUNT PROC FAR
MOV CX,16
MOV BX,0
L3:
SHR AX,1
JNC P1
INC BL
P1:
LOOP L3
RET
COUNT ENDP
START:
MOV AX,DATA
MOV DS,AX
MOV AX,STACK
MOV SS,AX
MOV SP,OFFSET TOS
MOV DX,OFFSET MSG1
MOV AH,9
INT 21H
MOV BX,0
MOV CX,4
GET:
MOV AH,1
INT 21H
MOV AH,0
CMP AL,'A'
JB CONT
SUB AL,7
CONT:
SUB AL,30H
PUSH AX
MOV AX,BX
MUL H16
POP BX
ADD BX,AX
LOOP GET
MOV AX,BX
CALL COUNT
NEXT:
MOV DX,OFFSET MSG2
MOV AH,9
INT 21H
MOV AX,BX
CALL CONVERT
MOV DX,OFFSET ANS
MOV AH,9
INT 21H
EXIT:
MOV AX,4C00H
INT 21H
CODE ENDS
END START
只能识别大写字母 A-F
ASSUME CS:CODE,DS:DATA,SS:STACK
DATA SEGMENT
TEMP DW ?
MSG1 DB 13,10,"PLEASE INPUT A HEX NUMBER : $"
MSG2 DB 10,13,"THE HEX NUMBER HAVE $"
ANS DB " 1 $"
ERR DB 'BKADBKS'
H16 DW 16
DATA ENDS
STACK SEGMENT
DB 128 DUP (0)
TOS DB '$'
STACK ENDS
CODE SEGMENT
; 十六进制转换十进制
CONVERT PROC
MOV BL,10
MOV CX,0
L:
DIV BL
ADD AH,30H
INC CX
PUSH AX
MOV AH,0
CMP AL,0
JNZ L
O:
POP DX
MOV DL,DH
MOV DH,0
MOV AH,2
INT 21H
LOOP O
RET
CONVERT ENDP
;统计AX中1的个数,结果在BX中,用循环位移实现
COUNT PROC FAR
MOV CX,16
MOV BX,0
L3:
SHR AX,1
JNC P1
INC BL
P1:
LOOP L3
RET
COUNT ENDP
START:
MOV AX,DATA
MOV DS,AX
MOV AX,STACK
MOV SS,AX
MOV SP,OFFSET TOS
MOV DX,OFFSET MSG1
MOV AH,9
INT 21H
MOV BX,0
MOV CX,4
GET:
MOV AH,1
INT 21H
MOV AH,0
CMP AL,'A'
JB CONT
SUB AL,7
CONT:
SUB AL,30H
PUSH AX
MOV AX,BX
MUL H16
POP BX
ADD BX,AX
LOOP GET
MOV AX,BX
CALL COUNT
NEXT:
MOV DX,OFFSET MSG2
MOV AH,9
INT 21H
MOV AX,BX
CALL CONVERT
MOV DX,OFFSET ANS
MOV AH,9
INT 21H
EXIT:
MOV AX,4C00H
INT 21H
CODE ENDS
END START
全部回答
- 1楼网友:深街酒徒
- 2021-03-02 09:19
方法比较笨,但功能能实现。
datas segment
datas ends
stacks segment
cly macro ;宏定义cly,回车换行
mov dl,0dh
mov ah,2
int 21h
mov dl,0ah
mov ah,2
int 21h
endm
stacks ends
codes segment
assume cs:codes,ds:datas,ss:stacks
start:
mov ax,datas
mov ds,ax
mov bx,0
mov cx,4
loop1:
mov ah,1
int 21h
cmp al,'0'
jz let0
cmp al,'1'
jz let1
cmp al,'2'
jz let2
cmp al,'3'
jz let3
cmp al,'4'
jz let4
cmp al,'5'
jz let5
cmp al,'6'
jz let6
cmp al,'7'
jz let7
cmp al,'8'
jz let8
cmp al,'9'
jz let9
cmp al,'a'
jz leta
cmp al,'b'
jz letb
cmp al,'c'
jz letc
cmp al,'d'
jz letd
cmp al,'e'
jz lete
cmp al,'f'
jz letf
let0:
add bx,0
jmp let
let1:
add bx,1
jmp let
let2:
add bx,1
jmp let
let3:
add bx,2
jmp let
let4:
add bx,1
jmp let
let5:
add bx,2
jmp let
let6:
add bx,2
jmp let
let7:
add bx,3
jmp let
let8:
add bx,1
jmp let
let9:
add bx,2
jmp let
leta:
add bx,2
jmp let
letb:
add bx,3
jmp let
letc:
add bx,2
jmp let
letd:
add bx,3
jmp let
lete:
add bx,3
jmp let
letf:
add bx,4
let:
dec cx
jnz loop1
cly
mov ax,bx
mov cx,0
mov bx,10
shuchu2:
mov dx,0
inc cx
idiv bx ;商存入ax,余数存入dx
push dx ;保存余数
cmp ax,0
jnz shuchu2
shuchu3:
pop ax ;取出余数,放入ax
add ax,0030h
mov dl,al ;输出1的个数
mov ah,2
int 21h
loop shuchu3
mov ah,4ch
int 21h
codes ends
end start
- 2楼网友:患得患失的劫
- 2021-03-02 09:07
额,这个貌似包含汇编语言版的进制转换和移位操作
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯