一道汇编语言的题目。。求高手来解答
在内存数据段存储器中,从ADDR单元开始存有一个字符串,它以“$”符号作为结束标志,试编写程序统计该字符串的长度($字符不计入长度),并把长度值存入LETH字单元。...
在内存数据段存储器中,从ADDR单元开始存有一个字符串,它以“$”符号作为结束标志,试编写程序统计该字符串的长度($字符不计入长度),并把长度值存入LETH字单元。
展开
2个回答
展开全部
统计字符串并显示。
;----------------------------------------
;统计字符串的长度(最多能统计255个字符)
data SEGMENT
str DB 'I love you forever$'
data ENDS
;----------------------------------------
code SEGMENT
assume CS:code, DS:data
start:
MOV AX, data
MOV DS, AX
SUB AX, AX
LEA SI, str
compar:
MOV BL, [SI]
CMP BL, '$'
JZ binidec
INC AL
INC SI
JMP compar
binidec:
MOV BL, AL
MOV CL, 10d
CALL div_dec
MOV CL, 1d
CALL div_dec
MOV AH,4ch
INT 21h
;----------------------------------------
div_dec PROC near
MOV AL, BL
CBW
DIV CL
MOV BL, AH
MOV DL, AL
ADD DL, 30h
MOV AH, 02h
INT 21h
RET
div_dec ENDP
;----------------------------------------
code ENDS
END start
;----------------------------------------
;----------------------------------------
;统计字符串的长度(最多能统计255个字符)
data SEGMENT
str DB 'I love you forever$'
data ENDS
;----------------------------------------
code SEGMENT
assume CS:code, DS:data
start:
MOV AX, data
MOV DS, AX
SUB AX, AX
LEA SI, str
compar:
MOV BL, [SI]
CMP BL, '$'
JZ binidec
INC AL
INC SI
JMP compar
binidec:
MOV BL, AL
MOV CL, 10d
CALL div_dec
MOV CL, 1d
CALL div_dec
MOV AH,4ch
INT 21h
;----------------------------------------
div_dec PROC near
MOV AL, BL
CBW
DIV CL
MOV BL, AH
MOV DL, AL
ADD DL, 30h
MOV AH, 02h
INT 21h
RET
div_dec ENDP
;----------------------------------------
code ENDS
END start
;----------------------------------------
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
data segment
addr db 'bdfjdhjfhefkek....','$'
leth dw 0
data ends
code segment
main proc far
assume cs:code,ds:data
start:
MOV AX,DATA
MOV DS,AX
MOV BX,OFFSET ADDR
MOV CX,0
NEXT:
MOV AL,[BX]
CMP AL,'$'
JE END_A
INC CX
INC BX
JMP NEXT
END_A:
MOV BX,OFFSET LETH
MOV [BX],CX
RET
main endp
code ends
end start
addr db 'bdfjdhjfhefkek....','$'
leth dw 0
data ends
code segment
main proc far
assume cs:code,ds:data
start:
MOV AX,DATA
MOV DS,AX
MOV BX,OFFSET ADDR
MOV CX,0
NEXT:
MOV AL,[BX]
CMP AL,'$'
JE END_A
INC CX
INC BX
JMP NEXT
END_A:
MOV BX,OFFSET LETH
MOV [BX],CX
RET
main endp
code ends
end start
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询