ASSUME DS:seg1, CS:seg2\x0d\x0a\x0d\x0aseg1 SEGMENT\x0d\x0afirst DB 5,-8,3,9,-2,-5,7,-9,0,5,4,9,-6,1,-1,8,-3,6,2,-7,0,-4\x0d\x0aLEN_first EQU $ - first\x0d\x0a\x0d\x0asecond DB 30 DUP(?)\x0d\x0a\x0d\x0aseg1 ENDS\x0d\x0a \x0d\x0aseg2 SEGMENT\x0d\x0astart:\x0d\x0aMOV AX, seg1\x0d\x0aMOV DS, AX\x0d\x0a--------------------------下面是复制\x0d\x0a\x0d\x0a2.复制\x0d\x0a将first行中的非负数复制到second行\x0d\x0a\x0d\x0aMOV SI, 0\x0d\x0aMOV DI, 0\x0d\x0aMOV CX, LEN_first\x0d\x0aLOP:\x0d\x0aMOV AL, first [SI]\x0d\x0aCMP AL, 80H\x0d\x0aJNB NEXT\x0d\x0aMOV second [DI], AL\x0d\x0aINC DI\x0d\x0aNEXT:\x0d\x0aINC SI\x0d\x0aLOOP LOP\x0d\x0a\x0d\x0a--------------------------下面是排序\x0d\x0a\x0d\x0a3.排序\x0d\x0a将second行中的数据按升序重新排列。\x0d\x0a\x0d\x0aMOV CX, DI\x0d\x0aDEC CX\x0d\x0aLP1:\x0d\x0aPUSH CX\x0d\x0aMOV SI, 0\x0d\x0aLP2:\x0d\x0aMOV AL, second [SI]\x0d\x0aCMP AL, second [SI + 1]\x0d\x0aJB NEXT2\x0d\x0aXCHG AL, second [SI + 1]\x0d\x0aMOV second [SI], AL\x0d\x0aNEXT2:\x0d\x0aINC SI\x0d\x0aLOOP LP2\x0d\x0aPOP CX\x0d\x0aLOOP LP1\x0d\x0a\x0d\x0a--------------------------下面是结束程序\x0d\x0a\x0d\x0aEXIT:\x0d\x0aMOV AH, 4CH\x0d\x0aINT 21H\x0d\x0a\x0d\x0aseg2 ENDS\x0d\x0aEND startassume
cs:code,ds:data
data
segment
bcd
db
01h,23h,45h,67h,89h,13h,24h,35h,46h,57h
bcd码
asc
db
20
dup(0)
转换之后存在这里
data
ends
code
segment
start:
mov
ax,data
mov
ds,ax
mov
cx,10
循环次数
lea
si,bcd
si指向bcd码
lea
di,asc
di指向转换之后的目标位置
next:
mov
al,[si]
取出bcd码
mov
dl,al
放dl保存
and
al,0fh
去掉高4位,先处理低位的bccd码
or
al,30h
转换成ascii码
mov
[di],al
存到目标位置
inc
di
修改目标地卖悔址指针
push
cx
要用到移位指令,需要cl寄存器,所以将循环次数进栈保存
mov
cl,4
移动4位滚配让
shr
dl,cl
将大局原bcd码的高位移到地4位上
or
dl,30h
转换成ascii码
mov
[di],dl
存入目标位置
inc
di
修改地址指针
inc
si
修改地址指针
pop
cx
循环次数出栈
loop
next
循环
mov
ax,4c00h
int
21h
code
ends
end
start
木西?我喜欢这名字
评论列表(0条)